我正在构建一个Python应用程序,不想强迫我的客户端安装Python和模块。
那么,是否有一种方法可以将Python脚本编译为独立的可执行文件?
我正在构建一个Python应用程序,不想强迫我的客户端安装Python和模块。
那么,是否有一种方法可以将Python脚本编译为独立的可执行文件?
当前回答
你可能喜欢py2exe。您还可以在其中找到在Linux上执行此操作的信息。
其他回答
使用py2exe……使用下面的设置文件:
from distutils.core import setup
import py2exe
from distutils.filelist import findall
import matplotlib
setup(
console = ['PlotMemInfo.py'],
options = {
'py2exe': {
'packages': ['matplotlib'],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll']
}
},
data_files = matplotlib.get_py2exe_datafiles()
)
对于Python 3.2脚本,唯一的选择是cx_Freeze。从资源中构建;否则行不通。
对于Python 2。我建议使用PyInstaller,因为它可以将Python程序打包到一个可执行文件中,而不像cx_Freeze那样输出库。
你可能喜欢py2exe。您还可以在其中找到在Linux上执行此操作的信息。
我喜欢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.