Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap_pex_env should support PEX_PATH #530

Closed
kwlzn opened this issue Jul 27, 2018 · 2 comments
Closed

bootstrap_pex_env should support PEX_PATH #530

kwlzn opened this issue Jul 27, 2018 · 2 comments
Assignees

Comments

@kwlzn
Copy link
Contributor

kwlzn commented Jul 27, 2018

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:

>>> pex_bootstrapper.bootstrap_pex_env('requests.pex')
>>> import requests
>>>

but it'd be nice if this "just worked" in the same fashion of the typical pex runtime entrypoint.

@jsirois
Copy link
Member

jsirois commented Jul 27, 2018

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.

@jsirois jsirois self-assigned this Aug 12, 2024
@jsirois
Copy link
Member

jsirois commented Aug 12, 2024

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'
>>>

@jsirois jsirois closed this as completed Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants