<分区>
我不想发布我的 python 项目,但是当我将它发送给某人时,他被迫安装我在我的 python 项目中使用的所有包。
有没有办法打包之类的,因为可能有些用户对pip或者python不是很熟悉。
问候
<分区>
我不想发布我的 python 项目,但是当我将它发送给某人时,他被迫安装我在我的 python 项目中使用的所有包。
有没有办法打包之类的,因为可能有些用户对pip或者python不是很熟悉。
问候
最佳答案
PyInstaller is a program that freezes (packages) Python programs into stand-alone executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX. Its main advantages over similar tools are that PyInstaller works with Python 2.7 and 3.4—3.7, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility.
即使用户没有安装 python,它也能正常工作。
Here来自 github 项目的示例。如您所见,您可以下载源代码,也可以下载包含用于运行项目的每个包的 zip。在此示例中,它包含许多文件,但您可以将所有内容打包到一个 .exe 文件中。
从 PyPI 安装 PyInstaller:
pip install pyinstaller
转到您的程序目录并运行:
pyinstaller yourprogram.py
这将在名为 dist 的子目录中生成包。
You can use
--onefile
argument in order to generate the bundle with only a single executable file.
您询问了如何获取用户发送的参数。这里有一些方法,或多或少方便:
关于python - 如何将 Python Project 打包成独立的可执行文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54212814/