question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python conda run incorrect environment path

See original GitHub issue

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>"

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
cswartzvicommented, Feb 10, 2022

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.

3reactions
karthiknadigcommented, Feb 10, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Terminal PATH variables in wrong order for Conda env
All conda-installed software is not picked up if there is a version of it in /usr/local/bin. Other terminal programs do not have this...
Read more >
python - PATH not updated correctly from conda activate in ...
I am using VSCodes terminal pane. I activate a conda environment. For some reason, the python command is still set to /usr/bin/python ,...
Read more >
Troubleshooting
Solution . Force reinstall conda. A useful way to work off the development version of conda is to run python setup.py ...
Read more >
CondaEnvironment@0 - Conda environment v0 task
Create and activate a Conda environment. ... Default: false. ... You can run scripts as subsequent build tasks that run Python, Conda, ...
Read more >
Using Python environments in VS Code
By default, any Python interpreter installed runs in its own global environment. They aren't specific to a particular project. For example, if you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found