pyinstaller your_script.py
--onefile(-F)
: 将所有依赖项打包成一个单独的可执行文件。pyinstaller --onefile your_script.py
--name your_custom_name
: 指定生成的可执行文件的名称。pyinstaller --name your_custom_name your_script.py
--icon=your_icon.ico
: 指定生成的可执行文件的图标。图标文件通常是 .ico 格式。pyinstaller --onefile --icon=your_icon.ico your_script.py
--hidden-import=module_name
: 手动添加缺失的依赖项pyinstaller --onefile --requirements=requirements.txt your_script.py
--requirements=requirements.txt
: 指定包含依赖项列表的文件。pyinstaller --onefile --requirements=requirements.txt your_script.py
--clean: 在打包前删除临时文件和输出目录。
--debug: 在调试模式下运行 PyInstaller。
--log-level: 指定日志级别,如 --log-level=DEBUG。
-w 是一个命令行选项,用于生成无控制台窗口的可执行文件。
-p 用于添加模块搜索路径。
Python
。然后,打开命令行或终端,并运行以下命令安装 PyInstaller
:pip install pyinstaller
Python 2.7
,Python 2.7
已经在2020年结束了官方支持。然而,PyInstaller 3.6.0
是最后一个官方宣布支持 Python 2.x
的版本。因此我们需要指定 PyInstaller
的版本,否则会安装失败。pip install pyinstaller==3.6.0
$ pyinstaller --onefile -p venv/Lib/site-packages 20231207.py
39 INFO: PyInstaller: 3.6
39 INFO: Python: 2.7.18
39 INFO: Platform: Windows-10-10.0.22621
39 INFO: wrote C:\Users\MQiuj\PycharmProjects\pythonProject\20231207.spec
40 INFO: UPX is not available.
45 INFO: Extending PYTHONPATH with paths
['C:\\Users\\MQiuj\\PycharmProjects\\pythonProject',
'C:\\Users\\MQiuj\\PycharmProjects\\pythonProject\\venv\\Lib\\site-packages',
'C:\\Users\\MQiuj\\PycharmProjects\\pythonProject']
45 INFO: checking Analysis
46 INFO: Building because pathex changed
46 INFO: Initializing module dependency graph...
46 INFO: Caching module graph hooks...
53 INFO: Caching module dependency graph...
61 INFO: running Analysis Analysis-00.toc
62 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
required by c:\python27\python.exe
115 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9635_none_acd031d7e1db7c28.manifest
167 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.9635_none ...
167 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9635_none_08e2c157a83ed5da.manifest
168 INFO: Searching for file msvcr90.dll
168 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9635_none_08e2c157a83ed5da\msvcr90.dll
168 INFO: Searching for file msvcp90.dll
168 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9635_none_08e2c157a83ed5da\msvcp90.dll
168 INFO: Searching for file msvcm90.dll
168 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9635_none_08e2c157a83ed5da\msvcm90.dll
219 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9635_none_acd031d7e1db7c28.manifest
219 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9635)
240 INFO: Analyzing C:\Users\MQiuj\PycharmProjects\pythonProject\20231207.py
951 INFO: Processing pre-safe import module hook urllib3.packages.six.moves
2621 INFO: Processing module hooks...
2621 INFO: Loading module hook "hook-httplib.py"...
2622 INFO: Loading module hook "hook-encodings.py"...
2865 INFO: Loading module hook "hook-certifi.py"...
2874 INFO: Looking for ctypes DLLs
2874 INFO: Analyzing run-time hooks ...
2875 INFO: Including run-time hook 'pyi_rth_certifi.py'
2877 INFO: Looking for dynamic libraries
2930 INFO: Looking for eggs
2930 INFO: Using Python library C:\WINDOWS\system32\python27.dll
2930 INFO: Found binding redirects:
[BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'amd64', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 9635), publicKeyToken=u'1fc8b3b9a1e18e3b')]
2933 INFO: Warnings written to C:\Users\MQiuj\PycharmProjects\pythonProject\build\20231207\warn-20231207.txt
2951 INFO: Graph cross-reference written to C:\Users\MQiuj\PycharmProjects\pythonProject\build\20231207\xref-20231207.html
2982 INFO: checking PYZ
2983 INFO: Building because toc changed
2983 INFO: Building PYZ (ZlibArchive) C:\Users\MQiuj\PycharmProjects\pythonProject\build\20231207\PYZ-00.pyz
3257 INFO: Building PYZ (ZlibArchive) C:\Users\MQiuj\PycharmProjects\pythonProject\build\20231207\PYZ-00.pyz completed successfully.
3288 INFO: checking PKG
3288 INFO: Building because toc changed
3288 INFO: Building PKG (CArchive) PKG-00.pkg
3384 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9635)
4298 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
4299 INFO: Bootloader c:\python27\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
4299 INFO: checking EXE
4300 INFO: Building because toc changed
4300 INFO: Building EXE from EXE-00.toc
4300 INFO: Appending archive to EXE C:\Users\MQiuj\PycharmProjects\pythonProject\dist\20231207.exe
4306 INFO: Building EXE from EXE-00.toc completed successfully.
-p
命令手动指定依赖打入。20231207.exe
运行,按照预期运行:pyinstaller
工具的使用以及常用参数,并结合实际案例进行实战将我们的 Pyhton
脚本打包为了 .exe
可执行文件。你好,我是 Lorin 洛林,一位 Java 后端技术开发者!座右铭:Technology has the power to make the world a better place.
我对技术的热情是我不断学习和分享的动力。我的博客是一个关于Java生态系统、后端开发和最新技术趋势的地方。
作为一个 Java 后端技术爱好者,我不仅热衷于探索语言的新特性和技术的深度,还热衷于分享我的见解和最佳实践。我相信知识的分享和社区合作可以帮助我们共同成长。
在我的博客上,你将找到关于Java核心概念、JVM 底层技术、常用框架如Spring和Mybatis 、MySQL等数据库管理、RabbitMQ、Rocketmq等消息中间件、性能优化等内容的深入文章。我也将分享一些编程技巧和解决问题的方法,以帮助你更好地掌握Java编程。
我鼓励互动和建立社区,因此请留下你的问题、建议或主题请求,让我知道你感兴趣的内容。此外,我将分享最新的互联网和技术资讯,以确保你与技术世界的最新发展保持联系。我期待与你一起在技术之路上前进,一起探讨技术世界的无限可能性。
保持关注我的博客,让我们共同追求技术卓越。