python / python/cpython

Windows virtual environment does not work correctly under WSL

Aberta
#124,139 2 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

topic-venv type-bug
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Localize o script de ativação da venv que contém a instrução case de uname mostrada e compare seu comportamento no WSL com as ramificações existentes do Cygwin e do MSYS. Verifique como o wslpath lida com o caminho da venv do Windows e, em seguida, confirme que ativar uma venv do Windows a partir do WSL define o valor correto de VIRTUAL_ENV e não causa regressões nos outros ambientes.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python, shell
Domínio
operating-systems, tooling
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.