我正在构建一个Python应用程序,不想强迫我的客户端安装Python和模块。

那么,是否有一种方法可以将Python脚本编译为独立的可执行文件?


当前回答

我被告知PyRun也是一个选项。它目前支持Linux, FreeBSD和Mac OS X。

其他回答

使用Cython转换为C、编译并链接GCC。

另一种方法是,用C语言编写核心函数(那些你想要使其难以反转的函数),编译它们并使用Boost。Python导入编译后的代码(而且代码执行速度更快)。然后使用上面提到的任何工具进行分发。

第三个选项是cx_Freeze,它是跨平台的。

是的,可以将Python脚本编译成独立的可执行文件。

PyInstaller可用于将Python程序转换为独立的可执行文件,适用于Windows、Linux、Mac OS X、FreeBSD、Solaris和AIX。它是推荐的转换器之一。

py2exe将Python脚本转换为Windows平台上的可执行文件。

Cython是Python编程语言和扩展的Cython编程语言的静态编译器。

您可以使用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.

你可能喜欢py2exe。您还可以在其中找到在Linux上执行此操作的信息。