如何将 Python 项目打包成独立的可执行文件?
How to package Python Project into a standalone executable?
我不想发布我的 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.
具体案例:
您询问了如何获取用户发送的参数。这里有一些方法,或多或少方便:
- 使用输入(),
- 使用配置文件,
- 使用默认参数。
如果你想部署你的应用程序必须 运行 在其他机器上。我真的建议你使用 docker。
您将在本地构建一个 docker 映像,其中包含您的应用程序和您需要的所有依赖项
用户只需安装 docker,获取您的 docker 图像并在他的机器上 运行 即可。
https://docs.docker.com/get-started/
如果要部署 python 应用程序,可以使用 cx_freeze 对其进行打包。它将为您提供一个可以执行的二进制文件
我不想发布我的 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.
具体案例:
您询问了如何获取用户发送的参数。这里有一些方法,或多或少方便:
- 使用输入(),
- 使用配置文件,
- 使用默认参数。
如果你想部署你的应用程序必须 运行 在其他机器上。我真的建议你使用 docker。 您将在本地构建一个 docker 映像,其中包含您的应用程序和您需要的所有依赖项 用户只需安装 docker,获取您的 docker 图像并在他的机器上 运行 即可。 https://docs.docker.com/get-started/
如果要部署 python 应用程序,可以使用 cx_freeze 对其进行打包。它将为您提供一个可以执行的二进制文件