Python | 用Pyinstaller打包发布exe应用

时间:2022-04-30 01:01:50

参考:https://jingyan.baidu.com/article/a378c960b47034b3282830bb.html

https://ask.csdn.net/questions/720080

https://blog.csdn.net/solarnanocar/article/details/82077484(如果不需要转化成单个exe文件,单单此条即可,亲测有效)

https://www.cnblogs.com/gopythoner/p/6337543.html

https://jingyan.baidu.com/article/bad08e1ed173d409c85121f8.html

需打包程序参考:https://www.cnblogs.com/msxh/p/4966899.html

D:\pythonWorkspace\test>pyinstaller.exe -F -w testa.py
INFO: PyInstaller: 3.4
INFO: Python: 3.7.
INFO: Platform: Windows--10.0.-SP0
INFO: wrote D:\pythonWorkspace\test\testa.spec
INFO: UPX is not available.
INFO: Extending PYTHONPATH with paths
['D:\\pythonWorkspace\\test', 'D:\\pythonWorkspace\\test']
INFO: checking Analysis
INFO: Building because D:\pythonWorkspace\test\testa.py changed
INFO: Initializing module dependency graph...
INFO: Initializing module graph hooks...
INFO: Analyzing base_library.zip ...
INFO: running Analysis Analysis-.toc
INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by d:\python\python.exe
INFO: Caching module hooks...
INFO: Analyzing D:\pythonWorkspace\test\testa.py
INFO: Processing pre-find module path hook distutils
INFO: Loading module hooks...
INFO: Loading module hook "hook-distutils.py"...
INFO: Loading module hook "hook-encodings.py"...
INFO: Loading module hook "hook-pkg_resources.py"...
INFO: Processing pre-safe import module hook win32com
INFO: Loading module hook "hook-pydoc.py"...
INFO: Loading module hook "hook-pygame.py"...
WARNING: Hidden import "pygame._view" not found!
INFO: Loading module hook "hook-pythoncom.py"...
INFO: Loading module hook "hook-pywintypes.py"...
INFO: Loading module hook "hook-sysconfig.py"...
INFO: Loading module hook "hook-win32com.py"...
INFO: Loading module hook "hook-xml.py"...
INFO: Looking for ctypes DLLs
INFO: Analyzing run-time hooks ...
INFO: Including run-time hook 'pyi_rth_pkgres.py'
INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
INFO: Looking for dynamic libraries
INFO: Looking for eggs
INFO: Using Python library d:\python\python37.dll
INFO: Found binding redirects:
[]
INFO: Warnings written to D:\pythonWorkspace\test\build\testa\warn-testa.txt
INFO: Graph cross-reference written to D:\pythonWorkspace\test\build\testa\xref-testa.html
INFO: checking PYZ
INFO: Building because toc changed
INFO: Building PYZ (ZlibArchive) D:\pythonWorkspace\test\build\testa\PYZ-.pyz
INFO: Building PYZ (ZlibArchive) D:\pythonWorkspace\test\build\testa\PYZ-.pyz completed successfully.
INFO: checking PKG
INFO: Building because toc changed
INFO: Building PKG (CArchive) PKG-.pkg
INFO: Building PKG (CArchive) PKG-.pkg completed successfully.
INFO: Bootloader d:\python\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
INFO: checking EXE
INFO: Rebuilding EXE-.toc because testa.exe missing
INFO: Building EXE from EXE-.toc
INFO: Appending archive to EXE D:\pythonWorkspace\test\dist\testa.exe
INFO: Building EXE from EXE-.toc completed successfully.

执行后能在下图路径中的dist文件夹内生成一个exe应用程序,我的是win10系统,经实验,这个应用程序在其他的win10电脑中可以运行,但在win7里不行,若有大神有解决方法,欢迎指点~

Python | 用Pyinstaller打包发布exe应用

D:\pythonWorkspace\test>pyinstaller -D -w testa.py
INFO: PyInstaller: 3.4
INFO: Python: 3.7.
INFO: Platform: Windows--10.0.-SP0
INFO: wrote D:\pythonWorkspace\test\testa.spec
INFO: UPX is not available.
INFO: Extending PYTHONPATH with paths
['D:\\pythonWorkspace\\test', 'D:\\pythonWorkspace\\test']
INFO: checking Analysis
INFO: checking PYZ
INFO: checking PKG
INFO: Bootloader d:\python\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
INFO: checking EXE
INFO: Building because console changed
INFO: Building EXE from EXE-.toc
INFO: Appending archive to EXE D:\pythonWorkspace\test\build\testa\testa.exe
INFO: Building EXE from EXE-.toc completed successfully.
INFO: checking COLLECT
WARNING: The output directory "D:\pythonWorkspace\test\dist\testa" and ALL ITS CONTENTS will be REMOVED! Continue? (y/n)y
INFO: Removing dir D:\pythonWorkspace\test\dist\testa
INFO: Building COLLECT COLLECT-.toc
INFO: Building COLLECT COLLECT-.toc completed successfully.

执行后,可在上图路径中的dist文件夹内生成一个testa文件夹,经压缩后就可发给他人电脑中运行了,我win10的系统发到win7上可以运行

Python | 用Pyinstaller打包发布exe应用

如果有你有其他的素材包,得把素材包复制到新生成的文件夹内,本人还不知道如何把素材包一起转化成单一的exe文件,望有路过的大神指点~

Python | 用Pyinstaller打包发布exe应用