vscode-python: Python conda run incorrect environment path

Behaviour

I get the following error when running pytest test discovery. It looked like the environment path is getting duplicated: envs/kevlar/envs/kevlar. I’m on the latest conda 4.11 and fully updated to the latest VSCode version. I’ve seen https://github.com/microsoft/vscode-python/issues/18486 and this seems related but the updates and solutions there have done nothing for me. I’ve also recreated the environment to see if a brand new environment would avoid this error.

 conda run -n kevlar --no-capture-output --live-stream python ~/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ./inla_explore -s --cache-clear
cwd: ./inla_explore
[ERROR 2022-1-9 14:32:9.956]: Error discovering pytest tests:
 r [Error]: 
EnvironmentLocationNotFound: Not a conda environment: /Users/tbent/.mambaforge/envs/kevlar/envs/kevlar


    at ChildProcess.<anonymous> (/Users/tbent/.vscode/extensions/ms-python.python-2022.0.1814523869/out/client/extension.js:32:39235)
    at Object.onceWrapper (events.js:422:26)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)

Expected vs. Actual

XXX

Steps to reproduce:

  1. Open the “Testing” panel.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.2
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
  • Value of the python.languageServer setting: Default
User Settings


defaultLS: {"defaultLSType":"Pylance"}

downloadLanguageServer: true

envFile: "<placeholder>"

venvPath: "<placeholder>"

venvFolders: "<placeholder>"

condaPath: "<placeholder>"

pipenvPath: "<placeholder>"

poetryPath: "<placeholder>"

languageServer: "Pylance"

linting
• enabled: true
• cwd: "<placeholder>"
• Flake8Args: "<placeholder>"
• flake8Enabled: false
• flake8Path: "<placeholder>"
• lintOnSave: true
• banditArgs: "<placeholder>"
• banditEnabled: false
• banditPath: "<placeholder>"
• mypyArgs: "<placeholder>"
• mypyEnabled: false
• mypyPath: "<placeholder>"
• pycodestyleArgs: "<placeholder>"
• pycodestyleEnabled: false
• pycodestylePath: "<placeholder>"
• prospectorArgs: "<placeholder>"
• prospectorEnabled: false
• prospectorPath: "<placeholder>"
• pydocstyleArgs: "<placeholder>"
• pydocstyleEnabled: false
• pydocstylePath: "<placeholder>"
• pylamaArgs: "<placeholder>"
• pylamaEnabled: false
• pylamaPath: "<placeholder>"
• pylintArgs: "<placeholder>"
• pylintPath: "<placeholder>"

sortImports
• args: "<placeholder>"
• path: "<placeholder>"

formatting
• autopep8Args: "<placeholder>"
• autopep8Path: "<placeholder>"
• provider: "black"
• blackArgs: "<placeholder>"
• blackPath: "<placeholder>"
• yapfArgs: "<placeholder>"
• yapfPath: "<placeholder>"

testing
• cwd: "<placeholder>"
• debugPort: 3000
• nosetestArgs: "<placeholder>"
• nosetestsEnabled: undefined
• nosetestPath: "<placeholder>"
• promptToConfigure: true
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• pytestPath: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: false
• autoTestDiscoverOnSaveEnabled: true

terminal
• activateEnvironment: true
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"

experiments
• enabled: true
• optInto: []
• optOutFrom: []

insidersChannel: "off"

tensorBoard
• logDirectory: "<placeholder>"

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 20 (7 by maintainers)

Most upvoted comments

This might not be directly related, but I am able to trigger the same error as @tbenthompson in the pytest test discovery if both the following conditions are met:

  • the conda package is installed in a local environment (I realize this isn’t recommended, but I was testing a conda CLI plugin)
  • vscode is launched from outside the local environment

Steps to reproduce:

  1. Create a new environment with conda create -n vscode-conda-repro python=3.9 pytest
  2. Fire up vscode via a launcher, taskbar, or command line without the vscode-conda-repro environment activated
  3. Make a simple test and select the vscode-conda-repro interpreter
  4. Run the pytest test discovery - OK
  5. Install conda conda install -n vscode-conda-repro conda and restart vscode
  6. Refresh pytest test discovery - ERROR
  7. Unstall conda conda uninstall -n vscode-conda-repro conda and restart vscode
  8. Refresh pytest test discovery - OK

Some notes:

  • If you activate vscode-conda-repro and launch vscode from the command line (code .) the error goes away
  • If you set python.condaPath to the correct conda path the error goes away
  • If you revert to v2021.12.1559732655 the error goes away
  • I also ran similar commands as https://github.com/microsoft/vscode-python/issues/18493#issuecomment-1034367439 from Output > Python with similar results - no errors when executed from the command line inside or outside the vscode-conda-repro environment

Perhaps this is a known issue? It seems to be mentioned here: https://devblogs.microsoft.com/python/python-in-visual-studio-code-february-2022-release/#improvements-when-using-anaconda

Edit: I am running ubuntu 20.04 on WSL2 if that matters for “special characters in file paths” as mentioned in the blog.

@cswartzvi @tbenthompson Thanks for the investigation and patience. We will discuss this internally and update on this.

@cswartzvi Thanks for the super useful info and explanation. I just checked and you are absolutely right that I have the conda package installed in all the environments that are causing the issue. Uninstalling conda from an env solves the issues. Now that I think about the symptoms it seems obvious that this is the problem!

While this is probably user error, it seems like a type of user error that the VSCode could easily either correct for or yell about.

If you need to you can revert to an older version of the extension using the gear icon next to the extension in the extensions view image