-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Python may startup fails if the home
variable in pyvenv.cfg
is inaccurate
#127440
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
Comments
I don't think it's a good idea to bypass That said, I do think the failure mode and error log are pretty bad. We should instead fail with a message explaining that there is a mismatch in the Python installation used to create the virtual environment, and the one being used to run it. We should also suggest using |
Thanks for the suggestion :) But >>> ./pylink -m venv ./bad_venv --upgrade
Error: Command '['/home/xx/tmp/bad_venv/bin/pylink', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1. Very few people use I'm not trying to bypass |
Don't you have access to the base Python interpreter? The venv upgrade command is meant to be run with that, not with venv interpreter. If not, I would like to see if we can figure out other way to deal with your use-case before opting for this approach. |
I guess this error has nothing to do with the base interpreter, it comes from: # Lib/venv/__init__.py
...
def _setup_pip(self, context):
"""Installs or upgrades pip in a virtual environment"""
self._call_new_python(context, '-m', 'ensurepip', '--upgrade',
'--default-pip', stderr=subprocess.STDOUT) The python used here is the python in the venv ( >>> python3 -VV
Python 3.10.12 (main, Nov 6 2024, 20:22:13) [GCC 11.4.0]
>>> which python3
/usr/bin/python3
>>> python3 -m venv --upgrade ./bad_venv/
Error: Command '['/home/xx/tmp/bad_venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1. |
I think we should treat this as a venv bug, it should check |
I found that the doc for
It seems that the doc assumes that the location to run python command is always in the Python installation directory (Normally, this is correct). Now we seem to expect |
After looking into this a bit more, I think your proposed solution is reasonable. To fix the root of the issue, though, I opened GH-127895. We can apply your solution to 3.12 and 3.13 as a bugfix, and move away from using |
Bug report
Bug description:
The problem comes from
getpath.py
. Whengetpath.py
cannot findSTDLIB_LANDMARKS
fromexecutable_dir
, it will setprefix
to thePREFIX
. If the directory set inPREFIX
does not exist, an error occurs.See details:
cpython/Modules/getpath.py
Lines 590 to 599 in 49f15d8
How to reproduce
Error message
We can find that
sys._base_executable
here is correct, butsys.base_prefix
is wrong.We could configure
base_prefix
through the real interpreter path, which is used to search for libraries that Python depends on.CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
base_executable
to detectprefix
andexec_prefix
#127441The text was updated successfully, but these errors were encountered: