microsoft / microsoft/vscode-python-environments

"Failed to create conda environment" after the env is actually created — conda info --envs --json no longer returns envs_dirs (conda 26.x)

未关闭
#1,766 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

triage-needed
主要语言
TypeScript
星标
138
派生
62
平均合并
1 天 4 小时
30 天内合并 PR
35

描述

Environment

Extension ms-python.vscode-python-envs 1.36.0
VS Code 1.136.1 (Windows 11, 10.0.26200)
conda 26.7.2 (miniforge3)

Steps to reproduce

  1. Python: Create EnvironmentCondaNamed (with an English display language).
  2. Pick a Python version, enter a name (test).

Actual

conda itself succeeds — the output channel shows the whole transaction completing:

Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
#
# To activate this environment, use
#
#     $ conda activate test

and then the extension fails:

[info]    Using conda from cache: C:\Users\...\miniforge3\Library\bin\conda.BAT
[info]    Ran conda in 697: C:\Users\...\miniforge3\Library\bin\conda.BAT info --envs --json
[warning] conda info envs_dirs is undefined/null
[error]   Failed to create conda environment A system error occurred
          (ENOENT: no such file or directory, scandir
           'C:\Users\...\AppData\Local\Programs\Microsoft VS Code\conda-meta')

The environment is created and fully usable. Only the post-creation prefix lookup fails — but the user is shown Failed to create conda environment, which reads as though nothing was created.

Cause

The env-dirs helper calls conda info --envs --json and reads envs_dirs from it:

const e = await H(["info", "--envs", "--json"]);
const t = JSON.parse(e);
const n = t.envs_dirs;
return null == n
    ? (traceWarn("conda info envs_dirs is undefined/null"), { envs_dirs: [] })
    : Array.isArray(n)
    ? { envs_dirs: n }
    : { envs_dirs: [] };

As of conda 26.x, conda info --envs --json returns only envs and envs_details. envs_dirs is present only in the unfiltered conda info --json:

$ conda info --envs --json
{
  "envs": [
    "C:\\Users\\...\\miniforge3",
    "C:\\Users\\...\\miniforge3\\envs\\test",
    ...
  ],
  "envs_details": { ... }
}
# no envs_dirs key

$ conda info --json | findstr envs_dirs
  "envs_dirs": [ ... ]

So envs_dirs becomes []. The empty list makes the subsequent prefix search join an empty base path, and conda-meta ends up resolved relative to the process cwd — VS Code's own install directory — which is the ENOENT above.

Aggravating factor

The empty result is cached, and the cache-hit check accepts an empty array:

const n = await e.get(CONDA_PREFIXES_KEY);
if (n && Array.isArray(n)) return j = n, j;   // [] passes this check
...
j = n.envs_dirs;                              // []
await e.set(CONDA_PREFIXES_KEY, ...);         // and gets cached

Once it has failed, the bad [] is served from cache on later attempts, so the failure persists until the cache is cleared.

Suggested fix

  • Read envs_dirs from conda info --json (or conda config --show envs_dirs --json) instead of conda info --envs --json.
  • Better still, derive the new environment's prefix from the envs array that the same response already returns — it contains the full path of the environment that was just created.
  • Treat an empty envs_dirs as a failure rather than a value: don't cache it, and require a non-empty array on the cache-hit path.

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先定位 issue 中描述的 env-dirs helper 以及 CONDA_PREFIXES_KEY 的 cache-hit 和 cache-write 路径。将 conda info --envs --json 的响应与未过滤的响应进行比较,然后验证创建环境时能够成功解析其 prefix,避免缓存空的 envs_dirs 值,并且不再报告虚假失败。

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

评估

技术栈
typescript, vscode
领域
developer-experience, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 发到你的邮箱

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