Closed cburroughs closed 7 months ago
@cburroughs, pex
will also drop you in a repl. That's how Pex works.
Perhaps this session using packaged Pex explains the behavior best:
$ python -mvenv example.venv
$ source example.venv/bin/activate
(example.venv) $ pip -q install -U pip
(example.venv) $ pip -q install -U ansicolors==1.1.7 cowsay==5.0 pex
(example.venv) $ python -c 'import colors; print(colors.__file__)'
/home/jsirois/example.venv/lib/python3.10/site-packages/colors/__init__.py
(example.venv) $ python -c 'import cowsay; print(cowsay.__file__)'
/home/jsirois/example.venv/lib/python3.10/site-packages/cowsay/__init__.py
(example.venv) $ cowsay --version
5.0
(example.venv) $ pex ansicolors cowsay
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import colors; print(colors.__file__)
/home/jsirois/.pex/installed_wheels/00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187/ansicolors-1.1.8-py2.py3-none-any.whl/colors/__init__.py
>>> import cowsay; print(cowsay.__file__)
/home/jsirois/.pex/installed_wheels/274b1e6fc1b966d53976333eb90ac94cb07a450a700b455af9fbdf882244b30a/cowsay-6.1-py3-none-any.whl/cowsay/__init__.py
>>>
now exiting InteractiveConsole...
(example.venv) $ pex ansicolors
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import colors; print(colors.__file__)
/home/jsirois/.pex/installed_wheels/00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187/ansicolors-1.1.8-py2.py3-none-any.whl/colors/__init__.py
>>> import cowsay; print(cowsay.__file__)
Traceback (most recent call last):
File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'cowsay'
>>>
now exiting InteractiveConsole...
(example.venv) $ pex
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import colors; print(colors.__file__)
Traceback (most recent call last):
File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'colors'
>>> import cowsay; print(cowsay.__file__)
Traceback (most recent call last):
File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'cowsay'
>>>
now exiting InteractiveConsole...
(example.venv) $
In other words, by default (with no -o / --output
, etc.) Pex resolves the requirements you request and drops you into a hermetic environment REPL with just access to those resolved requirements. You cannot access non-stdlib modules visible to the underlying interpreter the (ephemeral in this case) PEX is running under. So, if you supply 0 arguments (and thus 0 requirements), Pex drops you into a hermetic REPL exposing only the underlying Python's stdlib.
Does that make sense @cburroughs?
The behavior also caught me off guard back in 2010 and Wickman had to explain it to me. Now the behavior seems obvious, but I'm far removed from that Pex newb at this point.
@cburroughs I'll close this as an answered question unless you want to keep it open to change the run from source instructions.
From the README
-m pex.cli
appears to work. Not sure what is currently intended.