我正在构建一个Python应用程序,不想强迫我的客户端安装Python和模块。
那么,是否有一种方法可以将Python脚本编译为独立的可执行文件?
我正在构建一个Python应用程序,不想强迫我的客户端安装Python和模块。
那么,是否有一种方法可以将Python脚本编译为独立的可执行文件?
当前回答
你可能喜欢py2exe。您还可以在其中找到在Linux上执行此操作的信息。
其他回答
第三个选项是cx_Freeze,它是跨平台的。
我被告知PyRun也是一个选项。它目前支持Linux, FreeBSD和Mac OS X。
你可能想调查一下努伊特卡。它接受Python源代码并将其转换为c++ API调用。然后将其编译成可执行二进制文件(Linux上的ELF)。它已经存在了几年,并且支持广泛的Python版本。
如果使用它,您还可能获得性能改进。推荐使用。
您可以使用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.
我想编译一些关于使用Python 2.7在Windows上创建独立文件的有用信息。
我已经使用py2exe,它工作,但我有一些问题。
它已经显示了在Windows 64位中创建单个文件的一些问题:使用py2exe使用bundle_files = 1不起作用; 有必要创建一个setup.py文件以使其工作。http://www.py2exe.org/index.cgi/Tutorial步骤2; 我有依赖关系的问题,你必须通过导入安装文件中的包来解决; 我不能让它与PyQt一起工作。
最后一个原因让我尝试PyInstaller http://www.pyinstaller.org/。
在我看来,这样更好,因为:
它更容易使用。
我建议用以下代码创建一个。bat文件(pyinstaller.exe必须在Windows路径中):
pyinstaller.exe --onefile MyCode.py
在其他选项中,您可以创建单个文件(https://pyinstaller.readthedocs.io/en/stable/usage.html#options)。 我使用PyInstaller和多处理包时只有一个问题,通过使用这个配方解决了:https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing。
所以,我认为,至少对于python 2.7,一个更好更简单的选择是PyInstaller。