You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
venv on Windows with symlinks is broken if invoked with -I #86179
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-10-12.10:55:28.257>labels= ['3.10', '3.9', 'OS-windows']
title='venv on Windows with symlinks is broken if invoked with -I'updated_at=<Date2020-10-12.22:39:02.541>user='https://github.com/gaborbernat'
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
gaborbernat commented on Oct 12, 2020
gaborbernatmannequin
MannequinAuthor
More actions
We need more information about the specific environment this is triggering.
This issue is partly due to bpo-8901, which changed the behavior of the -E and -I command-line options to make them ignore the default PythonPath value in the registry key "Software\Python\PythonCore\X.Y\PythonPath". The change itself is not wrong. It's just exposing an underlying problem.
The home path in pyvenv.cfg is from sys._base_executable. In a launcher-based environment that's created from the base installation, sys._base_executable is the real base executable. OTOH, in a symlink-based virtual environment, sys._base_executable is the same as sys.executable. Consequently, if a virtual environment is created from a symlink-based virtual environment, the home path in pyvenv.cfg refers to the creating environment instead of the base installation. In this case, with the current implementation, the standard library can only be found by falling back on the default PythonPath in the registry.
Activity
gaborbernat commentedon Oct 12, 2020
Here's a small reproducible, run it on a Windows OS that has symlinks enabled:
# works
subprocess.check_call(["venv\\Scripts\\python.exe", "-c", "import sys; print(sys.executable)"])
# fails with No module named 'encodings'
subprocess.check_call(["venv\\Scripts\\python.exe", "-Ic", "import sys; print(sys.executable)"])
eryksun commentedon Oct 12, 2020
I can't reproduce the issue with the normal 3.9.0 distribution from python.org. For example:
>>> venv.EnvBuilder(with_pip=False, symlinks=True).create("venv") >>> subprocess.check_call(["venv\\Scripts\\python.exe", "-Ic", "import sys; print(sys.executable)"]) C:\Temp\env\venv\Scripts\python.exe 0Which Python version(s) and distribution(s) did you test? Do you have the PYTHONHOME and/or PYTHONPATH environment variables set?
gaborbernat commentedon Oct 12, 2020
❯ py -c 'import sys; print(sys.version)'
3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
FFY00 commentedon Oct 12, 2020
This error most likely happens because sys.path isn't being set properly and the standard library isn't being included.
We need more information about the specific environment this is triggering.
Which CPython build are you using? The one from Github Actions, right?
We also need the environment variables.
FFY00 commentedon Oct 12, 2020
Well, actually the environment variables /should/ not matter as -I implies -E.
gaborbernat commentedon Oct 12, 2020
Ok, the missing link is that the python you run into needs to be also a symlink venv:
❯ py -m venv env --without-pip --clear --symlinks
❯ .\env\Scripts\python.exe -c "import venv, subprocess; venv.EnvBuilder(with_pip=False, symlinks=True).create('venv'); subprocess.check_call(['venv\\Scripts\\python.exe', '-Ic', 'import sys; print(sys.executable)'])"
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
gaborbernat commentedon Oct 12, 2020
Both Gitub Actions Windows CPython3.9 or installer as downloaded from (on Windows 10) https://www.python.org/downloads/release/python-390/.
The issue manifests independent of those environment variables, netiher of them are set.
eryksun commentedon Oct 12, 2020
The operative word there is "should". I was grasping for anything that might explain why I couldn't reproduce the issue.
Thank you, that reproduces the problem for me.
eryksun commentedon Oct 12, 2020
This issue is partly due to bpo-8901, which changed the behavior of the -E and -I command-line options to make them ignore the default PythonPath value in the registry key "Software\Python\PythonCore\X.Y\PythonPath". The change itself is not wrong. It's just exposing an underlying problem.
The
homepath in pyvenv.cfg is from sys._base_executable. In a launcher-based environment that's created from the base installation, sys._base_executable is the real base executable. OTOH, in a symlink-based virtual environment, sys._base_executable is the same as sys.executable. Consequently, if a virtual environment is created from a symlink-based virtual environment, thehomepath in pyvenv.cfg refers to the creating environment instead of the base installation. In this case, with the current implementation, the standard library can only be found by falling back on the default PythonPath in the registry.16 remaining items
pythongh-86179: Implement realpath() on Windows for getpath.py calcul…
zooba commentedon Dec 14, 2023
I'm hesitant to backport the fix, since people always get upset when we change initialisation paths at all.
If anyone has a strong case for backporting, let me know. Otherwise I'll close this and #113121 in a few days and just call it done.
vsalvino commentedon Dec 14, 2023
I think as long as the fix is applied in 3.12 or 3.13, that's fine, it doesn't need to be backported to older versions.
zooba commentedon Dec 15, 2023
3.13 is where the fix will be. Going to 3.12 would be a backport.
pythongh-86179: Avoid making case-only changes when calculating realp…
pythongh-86179: Skip test case that fails on POSIX with unversioned b…
gh-86179: Skip test case that fails on POSIX with unversioned binary (G…
pythongh-86179: Skip test case that fails on POSIX with unversioned b…
pythongh-86179: Implement realpath() on Windows for getpath.py calcul…
pythongh-86179: Avoid making case-only changes when calculating realp…
pythongh-86179: Skip test case that fails on POSIX with unversioned b…
pythongh-86179: Implement realpath() on Windows for getpath.py calcul…
pythongh-86179: Avoid making case-only changes when calculating realp…
pythongh-86179: Skip test case that fails on POSIX with unversioned b…