Skip to content

pip's subprocesses have different module search path from parent process. #12309

@haampie

Description

@haampie

Description

Pip creates subprocesses, such as this one which runs hooks:

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions