TL;博士
我根据指南构建了
pex
https://pex.readthedocs.io/en/v2.1.145/buildingpex.html并期望它在我用来构建它的virtualenv之外运行良好,但是唉:
$ ~/bin/pex
env: python3.9: No such file or directory
我尝试过的
我正在阅读 pex 的指南 https://pex.readthedocs.io/en/v2.1.145/buildingpex.html 并按照他们的第一个“食谱”来构建
pex
本身
您可以使用 pex 实用程序构建 .pex 文件,该实用程序在您 pip install pex 时可用。 在 virtualenv 中执行此操作,然后您可以使用 pex 来引导自身:
venv
$ python3 -m venv venv
venv
$ . venv/bin/activate
pex
(venv) tmp $ pip install pex
Collecting pex
Downloading pex-2.1.145-py2.py3-none-any.whl (2.9 MB)
|████████████████████████████████| 2.9 MB 4.1 MB/s
Installing collected packages: pex
Successfully installed pex-2.1.145
pex
$ pex pex requests -c pex -o ~/bin/pex
pex
$ pex
Python 3.9.6 (default, May 7 2023, 23:32:44)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> ^D
now exiting InteractiveConsole...
您可以在任何 virtualenv 内部或外部使用 pex。
venv
,然后尝试再次运行 pex
:$ deactivate
$ ~/bin/pex
env: python3.9: No such file or directory
我错过了什么?
其他信息
平台:MacOS Ventura 13.5.1
感谢这个问题我了解了
--python-shebang
选项。
就我而言,我首先搜索了系统上Python 3解释器的路径:
$ which python3
/usr/bin/python3
然后在 VirtualEnv 中重新构建
pex
,但在我的系统上使用 Python 3 路径指定 shebang 行:
$ pex pex requests -c pex -o ~/bin/pex --python-shebang '#!/usr/bin/env python3'
现在我可以退出 VirtualEnv 并且
pex
仍然可以工作:
$ deactivate
$ ~/bin/pex
Python 3.9.6 (default, May 7 2023, 23:32:44)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> ^D
now exiting InteractiveConsole...