https://pantsbuild.org/ logo
#general
Title
# general
s

sparse-lifeguard-95737

12/06/2022, 9:49 PM
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

enough-analyst-54434

12/06/2022, 9:53 PM
Have you read the script shebangs?
s

sparse-lifeguard-95737

12/06/2022, 9:54 PM
I have not 🙂 you mean the shebang for the script having problems?
e

enough-analyst-54434

12/06/2022, 9:54 PM
Yes
I'm allowing you the pleasure of finding things out.
s

sparse-lifeguard-95737

12/06/2022, 9:56 PM
oho
E
passed to
python
e

enough-analyst-54434

12/06/2022, 9:56 PM
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

sparse-lifeguard-95737

12/06/2022, 10:07 PM
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

sparse-lifeguard-95737

12/07/2022, 2:32 PM
opened https://github.com/pantsbuild/pex/issues/2004 - if you’re 👍 to the idea, I can take a crack at the implementation
e

enough-analyst-54434

12/07/2022, 4:32 PM
Thanks, SGTM.
4 Views