python / python/cpython

Windows virtual environment does not work correctly under WSL

Open
#124,139 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-venv type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

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-is
        export 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.

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs
  • gh-124155

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the venv activation script containing the shown uname case statement and compare its behavior under WSL with the existing Cygwin and MSYS branches. Check how wslpath handles the Windows venv path, then verify that activating a Windows venv from WSL sets the correct VIRTUAL_ENV value and does not regress the other environments.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, shell
Domain
operating-systems, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.