Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension fails to activate unnamed conda environments #24095

Closed
F1bos opened this issue Sep 11, 2024 · 7 comments
Closed

Extension fails to activate unnamed conda environments #24095

F1bos opened this issue Sep 11, 2024 · 7 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@F1bos
Copy link

F1bos commented Sep 11, 2024

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:

  • VS Code version: Version: 1.93.0 (user setup)
  • Python extension version: v2024.14.0
  • Conda version: 24.7.1
  • Operating System: Ubuntu 20.04.3 LTS in WSL 2

Additional information:

  • This issue only occurs with unnamed conda environments. Named environments activate correctly.
  • The issue appeared after updating VS Code and the Python extension today. Previously, unnamed environments worked as expected.
  • It seems the problem might lie in the conda run command used by the extension. The logs show it's attempting to activate an environment named "env", but the unnamed environment doesn't have a name and is located at "./env", not "/home/USER/miniconda3/envs/env".

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.

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 11, 2024
@anthonykim1
Copy link

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

@anthonykim1 anthonykim1 added area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug and removed triage-needed Needs assignment to the proper sub-team labels Sep 16, 2024
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Sep 16, 2024
@F1bos
Copy link
Author

F1bos commented Sep 17, 2024

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

@Mrfence97
Copy link

I get the same issue running v2024.14.1 on Windows 11.

It appears that the folder name containing the unnamed environment is now being passed to the conda activate command in isolation. For example, if the environment is created in a subfolder (e.g. conda create -p ./local/env), then the command run in the terminal is still conda activate env rather than the expected conda activate ./local/env.

@anthonykim1
Copy link

Can you try setting the setting for "native locator" to js instead of native?

@Mrfence97
Copy link

That fixed the issue for me @anthonykim1. It now runs conda activate <absolute path to environment>.

Copy link

github-actions bot commented Nov 4, 2024

Hey @anthonykim1, this issue might need further attention.

@F1bos, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@F1bos
Copy link
Author

F1bos commented Nov 4, 2024

Can you try setting the setting for "native locator" to js instead of native?

Thanks, it worked.

@F1bos F1bos closed this as completed Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants