python - 如何将 Python Project 打包成独立的可执行文件?

标签 python pip package release

<分区>

我不想发布我的 python 项目,但是当我将它发送给某人时,他被迫安装我在我的 python 项目中使用的所有包。

有没有办法打包之类的,因为可能有些用户对pip或者python不是很熟悉。

问候

最佳答案

PyInstaller

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 文件中。

使用方法(Manual):

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

相关文章:

package - 子包中的可见性

Python re.sub() 不会替换所有匹配项

python - OpenERP - 不同 View 页面中字段的 onchange 方法?

python - 关闭并打开另一个窗口

python - 无法安装 "mediapipe"库

适用于 Windows 但不适用于 Ubuntu 的 Java 提示符

python - 在 linux "screen"中运行 Python 脚本会产生 "Cannot assign requested address"

python - 属性错误 : module 'collections' has no attribute 'MutableMapping'

python - Windows 7 上的 Tensorflow 安装错误

java - NoClassDefFound 表示找不到该类?