-
Notifications
You must be signed in to change notification settings - Fork 3.3k
pip's subprocesses have different module search path from parent process. #12309
Description
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
| python = self.python_executable | |
| self._subprocess_runner( | |
| [python, abspath(str(script)), hook_name, td], | |
| cwd=self.source_dir, | |
| extra_environ=extra_environ | |
| ) |
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:
python -S -m pip install --no-build-isolation ...the system and user site-packages directories are dropped from sys.path, only PYTHONPATH 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 is PYTHONNOUSERSITE=1, but that only disables user site-packages, not system site-packages -- it's equivalent to lowercase python -s, not python -S.
Expected behavior
If pip is executed under python -S, also run subprocesses with python -S.
Code of Conduct
- I agree to follow the PSF Code of Conduct.