You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currently, using pex_bootstrapper.bootstrap_pex_env() to bootstrap imports from an external pex inside of a running python intepreter does not appear to natively handle PEX_PATH:
[omerta xxx]$ pex requests -o requests.pex
[omerta xxx]$ pex flask -o flask.pex
[omerta xxx]$ python2.7
Python 2.7.13 (default, Mar 2 2017, 16:22:01)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys
>>> pex_filename = 'flask.pex'
>>> sys.path.insert(0, os.path.join(os.path.abspath(pex_filename), '.bootstrap'))
>>> from _pex import pex_bootstrapper
>>> os.environ['PEX_PATH'] = os.path.abspath('./requests.pex')
>>> pex_bootstrapper.bootstrap_pex_env(pex_filename)
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
a viable workaround for the moment is to call bootstrap_pex_env once per pex:
This is related to #525 where I ran into problems due to the non-uniformity of pex build and pex run re interpreter selection. I should cleanup #525 to include this.
I worked hard to rid the need for Pex API use since Pex only supports its CLI interface. With the introduction of the __pex__ magic import hook in #1845, you can now do this instead:
:; pex requests -o requests.pex
:; pex flask -o flask.pex
:; python
Python 3.11.9 (main, Apr 26 2024, 19:20:24) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys
>>> sys.path.insert(0, os.path.abspath("flask.pex"))
>>> os.environ['PEX_PATH'] = os.path.abspath("requests.pex")
>>> import __pex__
>>> import requests
>>> import flask
>>> requests.__file__
'/home/jsirois/.pex/installed_wheels/70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6/requests-2.32.3-py3-none-any.whl/requests/__init__.py'
>>> flask.__file__
'/home/jsirois/.pex/installed_wheels/34e815dfaa43340d1d15a5c3a02b8476004037eb4840b34910c6e21679d288f3/flask-3.0.3-py3-none-any.whl/flask/__init__.py'
>>>
currently, using
pex_bootstrapper.bootstrap_pex_env()
to bootstrap imports from an external pex inside of a running python intepreter does not appear to natively handlePEX_PATH
:a viable workaround for the moment is to call
bootstrap_pex_env
once per pex:but it'd be nice if this "just worked" in the same fashion of the typical pex runtime entrypoint.
The text was updated successfully, but these errors were encountered: