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

标签 python executable

这个问题在这里已经有了答案:





Create a single executable from a Python project

(3 个回答)


去年关闭。




我正在构建一个 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/65388382/

相关文章:

Python更改文件夹中多个文件的文件名

linux - npm 包未在 Linux 上执行

Python Windows `msvcrt.getch()` 只检测每 3 次按键?

python - celery 花在主管管理下不工作

.net - 为什么 UPX 不适用于 .NET 可执行文件?

c++ - 观看来自可执行文件的指令?

python - 是否有与 Python 的 `if __name__ == ' __main_ _'` 等效的 Perl?

java - 有没有一种方法可以让别人在看不到代码的情况下运行我的 Java 程序?

python - 如何通过 Selenium 和 Python 将文本按照 html 发送到文本区域

python - 所以我试图回答这个 : Given a list of ints, 如果数组在某处包含 3 旁边的 3 则返回 True