这个问题在这里已经有了答案:
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/