TL;DR
I built pex according to the guide https://pex.readthedocs.io/en/v2.1.145/buildingpex.html and was expecting it to run fine outside of the virtualenv I used to build it, but alas:
$ ~/bin/pex
env: python3.9: No such file or directory
What I tried
I am reading pex's guide https://pex.readthedocs.io/en/v2.1.145/buildingpex.html and following their first "recipe" to build pex itself
You can build .pex files using the pex utility, which is made available when you pip install pex. Do this within a virtualenv, then you can use pex to bootstrap itself:
- In an empty directory, I created a fresh
venv
$ python3 -m venv venv
- Activate the
venv
$ . venv/bin/activate
- Insatll
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
- Build
pex
$ pex pex requests -c pex -o ~/bin/pex
- Try
pexinteractively
$ 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...
- The documentation says:
you can use pex in or outside of any virtualenv.
- Therefore, I deactivate the
venvand then try to runpexagain:
$ deactivate
$ ~/bin/pex
env: python3.9: No such file or directory
What am I missing?
Additional information
Platform: MacOS Ventura 13.5.1
Thanks to this SO question I learned about the
--python-shebangoption.In my case, I first searched the path of the Python 3 interpreter on the system:
then re-built
pexinstide the VirtualEnv but specifying the shebang line with the Python 3 path on my system:Now I can exit the VirtualEnv and
pexstill works: