microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.29k stars 1.18k forks source link

Extension fails to activate unnamed conda environments #24095

Open F1bos opened 1 week ago

F1bos commented 1 week ago

Description:

Extension is unable to activate unnamed conda environments created using the conda create -p command after the latest update. Previously, these environments were activated correctly. No changes were made to the environments themselves, only VS Code and the Python extension were updated. Named conda environments continue to activate without issue.

Steps to reproduce:

  1. Create an unnamed conda environment using the following command:
    conda create -p ./env
  2. Open a project folder in VS Code that uses this unnamed environment.
  3. Attempt to select the environment as the Python interpreter for the project using the Python extension.

Expected behavior:

The Python extension should successfully activate the unnamed conda environment and correctly load its packages, as it did before the update.

Actual behavior:

The Python extension fails to activate the environment and displays an error message, indicating "EnvironmentLocationNotFound". The wrong Python interpreter may be selected, leading to issues with code execution and package resolution.

Logs:

2024-09-12 01:04:26.645 [error] getActivatedEnvironmentVariables Error: Command failed: conda run -n env --no-capture-output python /home/<USER>/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py /home/<USER>/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/printEnvVariables.py

EnvironmentLocationNotFound: Not a conda environment: /home/<USER>/miniconda3/envs/env

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at ChildProcess.exithandler (node:child_process:423:12)
    at ChildProcess.emit (node:events:531:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Pipe.<anonymous> (node:net:338:12) {
  code: 1,
  killed: false,
  signal: null,
  cmd: 'conda run -n env --no-capture-output python /home/<USER>/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/get_output_via_markers.py /home/<USER>/.vscode-server/extensions/ms-python.python-2024.14.0-linux-x64/python_files/printEnvVariables.py'
}

Environment:

Additional information:

I have tried restarting VS Code and reinstalling the Python extension, but the issue persists.

Please investigate this issue and provide a fix to restore the ability to activate unnamed conda environments within the Python extension.

anthonykim1 commented 6 days ago

Hi @F1bos Thanks for filing this issue. Can you try adding:

"python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"],

to your settings.json and see if that works? Thanks

F1bos commented 4 days ago

Hi @F1bos Thanks for filing this issue. Can you try adding:

"python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"],

to your settings.json and see if that works? Thanks

Hi.

This is what i have in Python extension logs:

2024-09-18 00:33:41.208 [info] Experiment 'pythonTerminalEnvVarActivation' is inactive
2024-09-18 00:33:41.208 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-09-18 00:33:41.208 [info] Experiment 'pythonTestAdapter' is active
2024-09-18 00:33:41.208 [info] Native locator: Refresh started
2024-09-18 00:33:41.208 [info] Default formatter is set to ms-python.black-formatter for workspace /home/user/projects/some_project
2024-09-18 00:33:42.549 [info] > pyenv which python
2024-09-18 00:33:42.549 [info] cwd: .
2024-09-18 00:33:42.567 [info] Conda environment manager found at: /home/user/miniconda3/bin/conda
2024-09-18 00:33:42.613 [info] Native locator: Refresh finished in 1548 ms
2024-09-18 00:33:42.627 [info] Python interpreter path: ./env/bin/python
2024-09-18 00:33:45.256 [info] Starting Pylance language server.
2024-09-18 00:33:45.268 [info] > ~/miniconda3/bin/conda info --json
2024-09-18 00:34:00.532 [info] Send text to terminal: conda activate env

This is what i got in terminal:

conda activate env
(miniconda3)user@DESKTOP:~/projects/some_project$ conda activate env

EnvironmentNameNotFound: Could not find conda environment: env
You can list all discoverable environments with `conda info --envs`.