我正在构建一个Python应用程序,不想强迫我的客户端安装Python和模块。
那么,是否有一种方法可以将Python脚本编译为独立的可执行文件?
我正在构建一个Python应用程序,不想强迫我的客户端安装Python和模块。
那么,是否有一种方法可以将Python脚本编译为独立的可执行文件?
当前回答
我也推荐使用PyInstaller以获得更好的向后兼容性,例如Python 2.3 - 2.7。
对于py2exe,你必须有Python 2.6。
其他回答
你可能想调查一下努伊特卡。它接受Python源代码并将其转换为c++ API调用。然后将其编译成可执行二进制文件(Linux上的ELF)。它已经存在了几年,并且支持广泛的Python版本。
如果使用它,您还可能获得性能改进。推荐使用。
不完全是Python代码的打包,但现在也有来自谷歌的Grumpy,它将代码编译到Go。
它不支持Python C API,因此可能不适用于所有项目。
我喜欢PyInstaller——尤其是“windowed”版本:
pyinstaller --onefile --windowed myscript.py
它将在distination/文件夹中创建一个*.exe文件。
您可以使用PyInstaller将Python程序打包为独立的可执行文件。它可以在Windows、Linux和Mac上运行。
PyInstaller Quickstart Install PyInstaller from PyPI: pip install pyinstaller Go to your program’s directory and run: pyinstaller yourprogram.py This will generate the bundle in a subdirectory called dist. pyinstaller -F yourprogram.py Adding -F (or --onefile) parameter will pack everything into single "exe". pyinstaller -F --paths=<your_path>\Lib\site-packages yourprogram.py running into "ImportError" you might consider side-packages. pip install pynput==1.6.8 still runing in Import-Erorr - try to downgrade pyinstaller - see Getting error when using pynput with pyinstaller For a more detailed walkthrough, see the manual.
您可以在“分布实用程序”中找到列出的分布实用程序列表。
我使用bbfreeze,它一直工作得很好(虽然还没有Python 3支持)。