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

PEX_PYTHON_PATH impacts interpreter selection for Pex installed from pip, but not the pex release file #1075

Open
Eric-Arellano opened this issue Oct 14, 2020 · 2 comments

Comments

@Eric-Arellano
Copy link
Contributor

Eric-Arellano commented Oct 14, 2020

Using pex installed via pip install pex, I get this behavior:

pex --interpreter-constraint='CPython>=3.5' -- -c "import sys, os; print(os.path.realpath(sys.executable))"
/Users/eric/.pyenv/versions/3.6.10/bin/python3.6
PEX_PYTHON_PATH=/Users/eric/.pyenv/versions/3.7.7/bin pex --interpreter-constraint='CPython>=3.5' -- -c "import sys, os; print(os.path.realpath(sys.executable))"
/Users/eric/.pyenv/versions/3.7.7/bin/python3.7

But using pex installed from the releases page, I get this behavior:

./pex --interpreter-constraint='CPython>=3.5' -- -c "import sys, os; print(os.path.realpath(sys.executable))"
/Users/eric/.pyenv/versions/3.6.10/bin/python3.6
PEX_PYTHON_PATH=/Users/eric/.pyenv/versions/3.7.7/bin ./pex --interpreter-constraint='CPython>=3.5' -- -c "import sys, os; print(os.path.realpath(sys.executable))"
/Users/eric/.pyenv/versions/3.6.10/bin/python3.6
@Eric-Arellano Eric-Arellano changed the title PEX_PYTHON_PATH impacts interpreter selection for Pex from pip, but not the pex release file PEX_PYTHON_PATH impacts interpreter selection for Pex installed from pip, but not the pex release file Oct 14, 2020
@Eric-Arellano
Copy link
Contributor Author

I now understand why setting PEX_PYTHON_PATH works when running Pex when installed via pip. Variables(rc=options.rc_file) ends up reading from os.environ still:

https://github.com/pantsbuild/pex/blob/20a67c3e95e4d15b9e200dc15e9b01aad2cbb83e/pex/variables.py#L184-L192

This means that unless the user explicitly has set PEX_IGNORE_RCFILES, PEX_PYTHON_PATH is already being used, regardless of RC files having been created. I'm not sure we were aware this happens.

--

It's not clear to me yet why the behavior is different when running Pex via the release page.

@Eric-Arellano
Copy link
Contributor Author

It's not clear to me yet why the behavior is different when running Pex via the release page.

Found it: #741. We strip PEX_PYTHON_PATH from os.environ when running ./pex. By the time we're building a new PEX, this env var has been stripped. Atm, the sole way to load PEX_PYTHON_PATH when building a new Pex by running ./pex is to use an RC File, which won't get stripped.

Eric-Arellano added a commit that referenced this issue Oct 15, 2020
…a PEX (#1077)

Closes #1012.

Currently, PEX defaults to searching the $PATH when `--interpreter-constraint` and/or `--resolve-local-platforms` are used. (Otherwise, it uses the current interpreter or `--python`).

You can specify `PEX_PYTHON_PATH`, but this has several issues:

* Env vars should only be used for runtime, not build time. We break that separation here.
* This only works if `PEX_IGNORE_RCFILES` is not set to true. Pants must set this option, meaning Pants cannot leverage this mechanism.
* The behavior doesn't work as expected if running Pex as a Pex: #1075

Instead of further using `PEX_PYTHON_PATH`, we add a proper `--python-path` flag. In a followup, we can remove the `PEX_PYTHON_PATH` mechanism.
@jsirois jsirois mentioned this issue Nov 10, 2020
4 tasks
This was referenced Dec 14, 2020
This was referenced Feb 1, 2021
@jsirois jsirois mentioned this issue Feb 17, 2021
1 task
@jsirois jsirois mentioned this issue Feb 25, 2021
5 tasks
This was referenced Mar 5, 2021
@jsirois jsirois mentioned this issue Mar 21, 2021
3 tasks
This was referenced Mar 29, 2021
@jsirois jsirois mentioned this issue Apr 5, 2021
2 tasks
This was referenced Apr 21, 2021
@jsirois jsirois mentioned this issue Apr 29, 2021
9 tasks
@jsirois jsirois mentioned this issue Jun 18, 2021
1 task
@jsirois jsirois mentioned this issue Jul 29, 2021
1 task
This was referenced Feb 12, 2023
This was referenced Feb 25, 2023
This was referenced Mar 7, 2023
@jsirois jsirois mentioned this issue Mar 23, 2023
2 tasks
@jsirois jsirois mentioned this issue Mar 30, 2023
2 tasks
This was referenced Apr 17, 2023
This was referenced May 1, 2023
@jsirois jsirois mentioned this issue May 13, 2023
2 tasks
@jsirois jsirois mentioned this issue Jul 1, 2023
3 tasks
This was referenced Jul 21, 2023
This was referenced Aug 3, 2023
@jsirois jsirois mentioned this issue Aug 12, 2023
1 task
This was referenced Aug 22, 2023
@jsirois jsirois mentioned this issue Sep 18, 2023
1 task
@jsirois jsirois mentioned this issue Sep 30, 2023
1 task
This was referenced Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant