debugging some strange behavior with a virtualenv ...
# general
s
debugging some strange behavior with a virtualenv created using
./pants export --symlink-python-virtualenv
🧵
in our repo, we have to
export PYTHONPATH=${REPO_ROOT}/src
to use
python
directly / to run scripts in the virtualenv
when using the symlinked venv, I’m seeing that
PYTHONPATH
is present in
os.environ
, but it’s not updating
sys.path
- only when running one of our custom binaries. the binary uses
importlib
to dynamically import other modules in our source, and this is failing with `ModuleNotFoundError`s
I’m able to import the modules if I drop into a REPL with
python
in the same venv
the custom binary is hacky AF so I am wondering if it’s a problem there, or if pants/pex are doing something when generating the venv such that
PYTHONPATH
ends up getting stripped from the env in certain cases
e
Have you read the script shebangs?
s
I have not 🙂 you mean the shebang for the script having problems?
e
Yes
I'm allowing you the pleasure of finding things out.
s
oho
E
passed to
python
e
Exactly
PEX == hermetic
So, you'll need to
PYTHONPATH=x venv/bin/python venv/bin/script
as things stand for that script.
It may make sense to add an option to the venv PEX_TOOL to be sloppy and not add -sE
s
hmmm yeah - this does seem to make the symlink-export case less useful. same problem bites
pylint
when it tries to load first-party plugins
granted we’d want people to
./pants lint
instead of running
pylint
directly, but trying to be flexible during the transition period 🤔
is https://github.com/pantsbuild/pex/blob/632a6ba3867d520e2721bf70fa1e7f114050c78b/pex/venv/pex.py#L98-L110 the right neighborhood for me to be reading through to grok the way things work now?
s
opened https://github.com/pantsbuild/pex/issues/2004 - if you’re 👍 to the idea, I can take a crack at the implementation
e
Thanks, SGTM.