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
Windows virtual environment does not work correctly under WSL #124139
Currently, Windows venvs work under cygwin because the activate script checks for it and converts the path as necessary. Cygwin is old and the new way to run a Linux shell on Windows is through the Windows Subsystem for Linux (WSL). However, there is no check for it in the script, making it not work correctly.
The relevant snippet from the script is:
# on Windows, a path can contain colons and backslashes and has to be converted:case"$(uname)"in
CYGWIN*|MSYS*)
# transform D:\path\to\venv to /d/path/to/venv on MSYS# and to /cygdrive/d/path/to/venv on Cygwin
VIRTUAL_ENV=$(cygpath "__VENV_DIR__")export VIRTUAL_ENV
;;
*)
# use the path as-isexport VIRTUAL_ENV="__VENV_DIR__"
;;
esac
I was able to easily fix it manually by changing the reference to my project's venv path with $(wslpath -u "__VENV_DIR__"). All we need is a check for WSL in the script and another prong on this case statement. The best way to do this is probably by searching for "microsoft" or "wsl" in the output of uname -r. Some work might be needed to ensure this covers all edge cases.
The robust fix is the approach virtualenv takes: derive VIRTUAL_ENV from the activate script's own location rather than detecting the shell and converting a baked-in path. virtualenv falls back to realpath "${BASH_SOURCE[0]}/../" when the recorded path isn't a directory, and only runs cygpath for Cygwin/MSYS/MINGW — never WSL: activate.sh L62-77.
That keys on "does the recorded path resolve here", which is the correct axis. A native Linux venv created in WSL keeps its POSIX path untouched, and a Windows venv sourced from WSL via its /mnt/... mount resolves to a working path with no wslpath and no WSL detection. Detecting WSL and calling wslpath instead converts unconditionally, so it also rewrites native Linux venvs created inside WSL.
One caveat regardless of approach: activation only sets VIRTUAL_ENV/PATH. The venv's Scripts/* shebangs and pyvenv.cfghome stay absolute, so a cross-mounted Windows venv still won't run its console scripts from WSL. The script-relative derivation is the right mechanism for the activation layer; the rest is a deeper, separate limitation.
(Also: this is labelled topic-repl; it looks like it should be topic-venv.)
It's also not Windows (WSL is a Linux virtual machine, so fixes belong to the Linux build, not the Windows build - at most, it's "generic"). And to contrast, Cygwin is Windows, but is also unsupported and largely relies on using their fork of CPython.
We made the Powershell activation script avoid using any embedded data so that it can be signed, perhaps there's value in making the other scripts similarly static?
Activity
gaborbernat commentedon Jun 5, 2026
The robust fix is the approach virtualenv takes: derive
VIRTUAL_ENVfrom the activate script's own location rather than detecting the shell and converting a baked-in path. virtualenv falls back torealpath "${BASH_SOURCE[0]}/../"when the recorded path isn't a directory, and only runscygpathfor Cygwin/MSYS/MINGW — never WSL: activate.sh L62-77.That keys on "does the recorded path resolve here", which is the correct axis. A native Linux venv created in WSL keeps its POSIX path untouched, and a Windows venv sourced from WSL via its
/mnt/...mount resolves to a working path with nowslpathand no WSL detection. Detecting WSL and callingwslpathinstead converts unconditionally, so it also rewrites native Linux venvs created inside WSL.One caveat regardless of approach: activation only sets
VIRTUAL_ENV/PATH. The venv'sScripts/*shebangs andpyvenv.cfghomestay absolute, so a cross-mounted Windows venv still won't run its console scripts from WSL. The script-relative derivation is the right mechanism for the activation layer; the rest is a deeper, separate limitation.(Also: this is labelled
topic-repl; it looks like it should betopic-venv.)zooba commentedon Jun 5, 2026
It's also not Windows (WSL is a Linux virtual machine, so fixes belong to the Linux build, not the Windows build - at most, it's "generic"). And to contrast, Cygwin is Windows, but is also unsupported and largely relies on using their fork of CPython.
We made the Powershell activation script avoid using any embedded data so that it can be signed, perhaps there's value in making the other scripts similarly static?