pyinstaller 打包


[root@localhost ~]# pip3 install pyinstaller
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pyinstaller
  Downloading https://files.pythonhosted.org/packages/9e/ed/fbdad7f5d8f794c901076b814b8e9f5ce31d32c0bc3b63ddd27b61db9530/pyinstaller-4.1.tar.gz (3.5MB)
    100% |████████████████████████████████| 3.5MB 370kB/s
Requirement already satisfied: setuptools in /usr/lib/python3.6/site-packages (from pyinstaller)
Collecting altgraph (from pyinstaller)
  Downloading https://files.pythonhosted.org/packages/ee/3d/bfca21174b162f6ce674953f1b7a640c1498357fa6184776029557c25399/altgraph-0.17-py2.py3-none-any.whl
Collecting pyinstaller-hooks-contrib>=2020.6 (from pyinstaller)
  Downloading https://files.pythonhosted.org/packages/2a/e6/4a47a7d41266cbca531bed3031c6412f9601ba2a2319e6d8c43f6917c51d/pyinstaller_hooks_contrib-2020.10-py2.py3-none-any.whl (166kB)
    100% |████████████████████████████████| 174kB 4.1MB/s
Installing collected packages: altgraph, pyinstaller-hooks-contrib, pyinstaller
  Running setup.py install for pyinstaller ... done
Successfully installed altgraph-0.17 pyinstaller-4.1 pyinstaller-hooks-contrib-2020.10
[root@localhost ~]# vim test.py
[root@localhost ~]# python3 test.py
hello world
[root@localhost ~]# python test.py
bash: python: command not found...
[root@localhost ~]# pyinstaller -F test.py
57 INFO: PyInstaller: 4.1
58 INFO: Python: 3.6.8
59 INFO: Platform: Linux-5.10.0-rc3-next-20201113-aarch64-with-centos-8.2.2004-Core
59 INFO: wrote /root/test.spec
61 INFO: UPX is not available.
62 INFO: Extending PYTHONPATH with paths
['/root', '/root']
74 INFO: checking Analysis
74 INFO: Building Analysis because Analysis-00.toc is non existent
74 INFO: Initializing module dependency graph...
75 INFO: Caching module graph hooks...
85 INFO: Analyzing base_library.zip ...
4668 INFO: Caching module dependency graph...
4781 INFO: running Analysis Analysis-00.toc
4794 INFO: Analyzing /root/test.py
4796 INFO: Processing module hooks...
4797 INFO: Loading module hook 'hook-difflib.py' from '/usr/local/lib/python3.6/site-packages/PyInstaller/hooks'...
4798 INFO: Excluding import of doctest from module difflib
4798 INFO: Loading module hook 'hook-encodings.py' from '/usr/local/lib/python3.6/site-packages/PyInstaller/hooks'...
4865 INFO: Loading module hook 'hook-heapq.py' from '/usr/local/lib/python3.6/site-packages/PyInstaller/hooks'...
4866 INFO: Excluding import of doctest from module heapq
4866 INFO: Loading module hook 'hook-pickle.py' from '/usr/local/lib/python3.6/site-packages/PyInstaller/hooks'...
4868 INFO: Excluding import of argparse from module pickle
4868 INFO: Loading module hook 'hook-xml.py' from '/usr/local/lib/python3.6/site-packages/PyInstaller/hooks'...
5223 INFO: Looking for ctypes DLLs
5223 INFO: Analyzing run-time hooks ...
5231 INFO: Looking for dynamic libraries
5466 INFO: Looking for eggs
5466 INFO: Using Python library /lib64/libpython3.6m.so.1.0
5469 INFO: Warnings written to /root/build/test/warn-test.txt
5499 INFO: Graph cross-reference written to /root/build/test/xref-test.html
5509 INFO: checking PYZ
5509 INFO: Building PYZ because PYZ-00.toc is non existent
5510 INFO: Building PYZ (ZlibArchive) /root/build/test/PYZ-00.pyz
5984 INFO: Building PYZ (ZlibArchive) /root/build/test/PYZ-00.pyz completed successfully.
5988 INFO: checking PKG
5988 INFO: Building PKG because PKG-00.toc is non existent
5988 INFO: Building PKG (CArchive) PKG-00.pkg
8297 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
8299 INFO: Bootloader /usr/local/lib/python3.6/site-packages/PyInstaller/bootloader/Linux-64bit-aarch/run
8299 INFO: checking EXE
8299 INFO: Building EXE because EXE-00.toc is non existent
8299 INFO: Building EXE from EXE-00.toc
8300 INFO: Appending archive to ELF section in EXE /root/dist/test
8307 INFO: Building EXE from EXE-00.toc completed successfully.

在ARM linux上运行:
[root@localhost dist]# ls
test
[root@localhost dist]# ./test
hello world

将其放到另一台linux上,内核版本不同的ARM linux上运行
[root@localhost ~]# uname -a
Linux localhost.localdomain 4.18.0-147.8.1.el8_1.aarch64+debug #1 SMP Thu Apr 9 13:52:42 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux
[root@localhost ~]# ./test
-bash: ./test: Permission denied
[root@localhost ~]# chmod 777 test
[root@localhost ~]# ./test
hello world


在x86 linux 上运行

tiantao@BoardServer2:~$ ./test
-bash: ./test: cannot execute binary file: Exec format error


卸载掉python3 ,test.py 已经无法执行了,但是pyinstaller打包的还是可以执行,说明打包后已经依赖python3
[root@localhost dist]# python3 test.py
-bash: /usr/bin/python3: No such file or directory
[root@localhost dist]# ./test
hello world

通过readelf 来看,这个test的已经是elf 格式的,这也证明了通过pyinstaller打包是分架构的
[root@localhost dist]# readelf -a test
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           AArch64
  Version:                           0x1
  Entry point address:               0x401a34
  Start of program headers:          64 (bytes into file)
  Start of section headers:          5683040 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         9
  Size of section headers:           64 (bytes)
  Number of section headers:         29
  Section header string table index: 28

猜你喜欢

转载自blog.csdn.net/tiantao2012/article/details/109838093