-
Notifications
You must be signed in to change notification settings - Fork 3k
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
pip's subprocesses have different module search path from parent process. #12309
Comments
FWIW, I don't immediately see public API for knowing whether So, either pip shouldn't run subprocesses, or it should accept some environment variable like |
Pip has to run subprocesses, it's essentially part of the PEP 517 specification. It's possible we should be more explicit about to what extent we "inherit" information from the parent process and to what extent we explicitly configure the subprocess ("the subprocess is not isolated using But taking a step back, why do you need this behaviour? What actual use case requires that pip copy the state of the In practical terms this seems like a rather niche requirement, given that we've basically had few if any requests for this over the years, so I'd like to see some evidence of how significant it is before putting too much time into designing an interface. |
For posterity, I suggested filing an issue about this over at spack/spack#40224. |
And, yea a more concise description of the use case would be appreciated. |
In Spack we resolve dependencies ourselves, so we want to avoid pip's "build isolation", since that would make pip do a separate solve + fetch + install of build deps. So, we use In principle this would be enough, even if the user has different versions of the same python packages installed in say However, things break when hooks are executed. For example setuptools does something along the lines of: for ep in importlib.metadata.entry_points(group="setuptools.finalize_distribution_options"):
ep.load()(self) This scans all installed packages for entrypoints, even those that aren't dependencies of the package to be installed. So, this could pick up some completely unrelated package in My hope was that just running
That's a workaround we currently implement. If Python itself is not installed by Spack, and may have system site-packages, we create a temporary virtual environment (let's call it a build environment), which drops user and system site-packages also in sub-processes. But this approach has a major downside, namely that upon installation, generated shebangs point to the temporary build environment, instead of the underlying python, so they have to be patched post-hoc. I don't see any way to prevent that. Hope that explains things. If you know of another approach that allows us to run pip w/o user/system site-packages search paths, and without the downside of broken shebangs, I'd be interested. |
So would an option to change the shebang lines work for you? That’s much less difficult, and IIRC it’s been requested before, so would help in more than just this case. |
Yeah, that would work 👍. Would be much better if pip did this, cause then
Do you know if apart from shebangs there are other instances where pip copies over the sys.executable path into some file? |
Related: #11483, #6278, #1351 (comment)
Probably in scripts in the |
Description
Pip creates subprocesses, such as this one which runs hooks:
pip/src/pip/_vendor/pyproject_hooks/_impl.py
Lines 310 to 315 in ff05e42
The issue is that this subprocess may run with different module search paths than the pip python process itself.
For example, when you run pip under
python -S
like this:the system and user site-packages directories are dropped from
sys.path
, onlyPYTHONPATH
and standard libs are considered.However, pip (or, vendored pyproject) then runs hooks by just executing
sys.executable
without the-S
flag, meaning that hooks from system and user site-packages are executed.There are no environment variables equivalent to
-S
. Closest isPYTHONNOUSERSITE=1
, but that only disables user site-packages, not system site-packages -- it's equivalent to lowercasepython -s
, notpython -S
.Expected behavior
If pip is executed under
python -S
, also run subprocesses withpython -S
.Code of Conduct
The text was updated successfully, but these errors were encountered: