Skip to content

Modernize virtual environments page - #2201

Open
konstin wants to merge 4 commits into
pypa:mainfrom
konstin:konsti/pyvenv-cfg-modernize
Open

konstin wants to merge 4 commits into
pypa:mainfrom
konstin:konsti/pyvenv-cfg-modernize

Conversation

@konstin

@konstin konstin commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Cleanup ahead of PEP 838.

  • Remove the references to PEP 405 in the text, PPO is the living spec page.
  • Remove the framing from PEP 405 that doesn't match current usage
  • Document the fields in pyvenv.cfg
  • Clarify that include-system-site-packages defaults to true

I left the parts that were previously vague as such, only removing those that are vague and misleading.


📚 Documentation preview 📚: https://python-packaging-user-guide--2201.org.readthedocs.build/en/2201/

@rgommers rgommers added component: specifications type: maintenance Regular maintenance of the guide, CI and repo labels Nov 22, 2026

@rgommers rgommers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @konstin. This looks good overall, I think I spotted one error and one opportunity to be more precise.

* ``include-system-site-packages``: When ``true``, the ``site`` module will
also add the system site directories to ``sys.path`` after the virtual
environment site directories. If ``false``, the system site directories are
not included. Defaults to ``true``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This true seems incorrect. PEP 405 says "By default, a virtual environment is entirely isolated from the system-level site-packages directories."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a CPython implementation thing where the key being absent makes it mean true, but it looks to me like the default should be false here.

EDIT: if changed, the History section needs the same edit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 405 is wrong, as you said CPython defaults to true and so tools treat it as such. The history entry for that correction I already added.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, did some digging. Looks like this was a bug in the original implementation in 2012 (this CPython commit) and then in 2018 when that bug was reported in python/cpython#6755, the response was that there was no need to change the implementation or PEP 405. So okay, I guess we're fine here.

That said, I think this is still confusing: what is described is the behavior when the key is absent. However, the default when a new venv is created by the venv module is still the opposite: then pyvenv.cfg will contain: include-system-site-packages = false. So I suggest a rephrasing like this:

If this key is absent, it defaults to true. The standard-library venv module explicitly writes false unless --system-site-packages is requested.

All other tools I checked (virtualenv, uv, Poetry, Pipenv, Hatch) also explicitly write out false. It's annoying that this key is optional; it'd be better to make it required because there is zero reason to keep it optional. Not sure if we want to fix this now, leave it with this clarification, or perhaps add a "RECOMMENDED for tools to explicitly write false".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that looks clear to me now. I will leave this comment thread unresolved for now; another reviewer may want to see it.

@rgommers rgommers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now, thanks @konstin. I think this improves the specification in both clarity and in fixing the historical error that was still present in PEP 405. Happy for this to go in; I'll leave it open for at least a few days because it touches Specifications, so useful for a second pair of eyes to check it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: specifications type: maintenance Regular maintenance of the guide, CI and repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants