diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 58ae85fb268042e..e7d5e890c1c31a4 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -146,6 +146,9 @@ def _check_output_of_default_create(self): self.assertIn('home = %s' % path, data) self.assertIn('executable = %s' % os.path.realpath(sys.executable), data) + self.assertIn("python-version = %d.%d" % (sys.version_info.major, + sys.version_info.minor), + data) copies = '' if os.name=='nt' else ' --copies' cmd = (f'command = {sys.executable} -m venv{copies} --without-pip ' f'--without-scm-ignore-files {self.env_dir}') diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index bd2762d55ef6961..0a96d11cb9baa3e 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -232,6 +232,8 @@ def create_configuration(self, context): incl = 'false' f.write('include-system-site-packages = %s\n' % incl) f.write('version = %d.%d.%d\n' % sys.version_info[:3]) + f.write('python-version = %d.%d\n' % (sys.version_info.major, + sys.version_info.minor)) if self.prompt is not None: f.write(f'prompt = {self.prompt!r}\n') f.write('executable = %s\n' % os.path.realpath(sys.executable)) diff --git a/Misc/NEWS.d/next/Library/2026-07-21-17-29-19.gh-issue-154377.pep838.rst b/Misc/NEWS.d/next/Library/2026-07-21-17-29-19.gh-issue-154377.pep838.rst new file mode 100644 index 000000000000000..e760a6f436bd11f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-21-17-29-19.gh-issue-154377.pep838.rst @@ -0,0 +1,2 @@ +Add a ``python-version`` key to ``pyvenv.cfg`` files created by :mod:`venv`. +This implements :pep:`838`.