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/49042978/

相关文章:

Python 脚本不与本地 Web 服务器一起运行,仅在浏览器中显示代码

python - Pandas 数据框分组并加入列

java - 使用NetBeans从Java项目制作可执行文件

python - 使用带有 pdist 和 squareform 的 nparray 创建距离矩阵

python - imshow() 和 matplotlib() 不能一起工作

python - 诗歌和 PyTorch

python - 如何使python程序 ".py"可执行?

gcc - Exec 格式错误 32 位可执行 Windows Linux 子系统?

c++ - 在 Web 执行模型中实现 EXE 时的设计选择

javascript - 使用canvas作为可执行文件运行javascript