python - 如何使 Python 脚本独立可执行文件在没有任何依赖关系的情况下运行?

标签 python executable

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

那么,有没有办法将 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 - 如何使 Python 脚本独立可执行文件在没有任何依赖关系的情况下运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5458048/

相关文章:

Python httplib.InvalidURL : nonnumeric port fail

python - 编辑 Dataframe Pandas 中的行数据

java - 如何创建一个 Makefile 来编译和运行带有命令行参数的 java 代码?

python - Python函数运行的可执行文件的终端输出如何以一般方式静音?

python - 解决 python 3 与 python 2 中的 map 函数问题

python - POST 到 google apis 计算引擎给出 400

python - Cython 中 complex.real 和 creal(complex) 的区别

MySQL 不是有效的 win32 应用程序

eclipse - 在 ECLIPSE java 中创建带有外部 jar (JXL) 的 jar 可执行文件

process - PowerBuilder 应用程序如何充当另一个 guest 可执行文件的宿主?