一文讲清 Python 打包工具 PyInstaller
warning:
这篇文章距离上次修改已过438天,其中的内容可能已经有所变动。
PyInstaller 是一个用于将 Python 程序打包成独立可执行文件的工具,它能够在 Windows、Linux、Mac OS X 等多种操作系统下工作。
安装 PyInstaller:
pip install pyinstaller打包 Python 程序:
pyinstaller your_script.py这将会生成dist/your\_script文件夹,里面包含了可执行文件。
如果你想要生成一个单独的可执行文件,可以使用--onefile选项:
pyinstaller --onefile your_script.py如果你的程序依赖数据文件,你可以使用--add-data选项来包含这些文件:
pyinstaller --add-data 'yourdatafile.dat;.' --onefile your_script.py如果你想要给生成的可执行文件加上图标,可以使用--icon选项:
pyinstaller --onefile --icon 'youricon.ico' your_script.py以上是 PyInstaller 的基本使用方法,具体使用时可以根据实际需求选择合适的选项。
评论已关闭