python / python/cpython

Windows virtual environment does not work correctly under WSL

未关闭
#124,139 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

topic-venv type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

定位包含所示 uname case 语句的 venv 激活脚本,并将其在 WSL 下的行为与现有的 Cygwin 和 MSYS 分支进行比较。检查 wslpath 如何处理 Windows venv 路径,然后验证从 WSL 激活 Windows venv 时是否设置了正确的 VIRTUAL_ENV 值,并且不会导致其他环境出现回归。

由索引模型根据 Issue 内容生成。

评估

技术栈
python, shell
领域
operating-systems, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。