pex:打包 Python 可执行文件
pex 代表 Python EXecutable,是一种生成易于分发的 python 包的方法。需要注意的一件重要事情是 pex 没有可靠的 Windows 支持。因此,您需要在 *NIX 系统上运行 pex。本文将展示您可以使用 pex 执行的一些操作,以分发不同类型的 python 项目。
基本用法
鉴于用于 pex 打包的 python 解释器很重要,强烈建议使用虚拟环境。作为示例,我将使用 python 3.11 环境:
$ virtualenv --python=python3.11 venv $ source venv/bin/activate $ python -m pip install pex Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting pex Using cached https://www.piwheels.org/simple/pex/pex-2.1.144-py2.py3-none-any.whl (2.9 MB) Installing collected packages: pex Successfully installed pex-2.1.144 登录后复制 进入全屏模式 退出全屏模式