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)

Đang mở
#1,766 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
triage-needed
Ngôn ngữ chính
TypeScript
Star
138
Fork
62
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
35

Mô tả

## 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 Environment** → **Conda** → **Named** (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:

```js
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`:

```console
$ 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:

```js
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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách tìm helper env-dirs và các luồng cache-hit và cache-write của CONDA_PREFIXES_KEY được mô tả trong issue. So sánh phản hồi của conda info --envs --json với phản hồi chưa được lọc, sau đó xác minh rằng việc tạo một environment sẽ resolve prefix của nó thành công, tránh cache một giá trị envs_dirs rỗng và không còn báo cáo lỗi giả nữa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript, vscode
Lĩnh vực
developer-experience, tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
68/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.