Skip to content

🐛 fix(create): drop PYTHONPATH from the debug interpreter - #3474

Merged
gaborbernat merged 2 commits into
pypa:mainfrom
RaphaelFakhri:fix-debug-pythonpath
Oct 27, 2026
Merged

gaborbernat merged 2 commits into
pypa:mainfrom
RaphaelFakhri:fix-debug-pythonpath

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

virtualenv collects the target environment's debug information (the target debug section of virtualenv -vv and Creator.debug) by running the new interpreter. It built a copy of the environment without PYTHONPATH for that run but then never passed it, so the child inherited the caller's full environment. 🐛 The reported sys.path listed the caller's PYTHONPATH entries, and the env given to cli_run had no effect on this process. After this change the debug interpreter runs with the filtered copy of the environment given to the creator.

The shared subprocess helper accepts an optional environment and forwards it to the child. Every other caller still inherits the process environment.

The debug interpreter now sees only the variables in the environment given to the creator, minus PYTHONPATH. When cli_run receives a custom env, that mapping now reaches this process too.

Thanks for contributing, make sure you address all the checklists (for details on how see development documentation)

  • ran the linter to address style issues (tox -e fix) (ruff, typos and ty on the changed files)

  • wrote descriptive pull request text

  • ensured there are test(s) validating the fix

  • added a docs/changelog/+short-description.<type>.rst fragment for each user-facing change, or applied skip news

  • updated/extended the documentation (not needed, no documented behavior changes)

  • for changes to activation scripts, pyvenv.cfg, wheel downloads, app-data or release workflows: explained in the PR text which outside input the change handles, such as a path, a prompt or a downloaded file, and how it stops that input from running as code. See the security scope. (not applicable)

  • ran tests on Python 3.9 and 3.15 (tox run -e 3.9,3.15) (ran on 3.12; CI covers the matrix)

  • linked upstream issues beside any temporary interpreter overrides (not applicable)

  • kept the PR in draft until CI passes

Fixes #3473

Annotate the fixtures, mark the locals Final and create the session right
before the assertion that reads it.
@gaborbernat
gaborbernat merged commit 3def145 into pypa:main Oct 27, 2026
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The target debug information reports PYTHONPATH entries in sys.path

2 participants