Repository navigation
Python conda run incorrect environment path #18493
Copy link
Copy link
Closed as not planned
Labels
area-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
Description
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 #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:
- 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.languageServersetting: 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>"
Reacted by Caleb Ho, Charles Swartz, Joel Dunstan, Richard Höchenberger, Samantha Hughes, Nicholas Steiner, hassell-nmm, Andrés Marafioti, Alan Silva, Steven DeMartini and 1 more
Metadata
Metadata
Assignees
Labels
area-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
Activity
calebho commentedon Feb 9, 2022
+1, also seeing the same error.
Extension version:
v2022.0.1814523869Conda version:
4.11.0karthiknadig commentedon Feb 9, 2022
That is an issue with conda itself. Previous versions of the extension were using a hack. That hack no longer works starting conda 4.10. we decided to use the
conda runas that was recommend way to run scripts using conda. Please file a bug https://github.com/conda/conda/issueskarthiknadig commentedon Feb 9, 2022
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

tbenthompson commentedon Feb 9, 2022
Are you sure about this? When I run the exact same command as vscode in a terminal, the command runs just fine. That leads me to believe this is some kind of error in the extension's shell environment setup.
karthiknadig commentedon Feb 9, 2022
Is there a difference between the environment variables in the VS Code terminal VS the external terminal? What happens if you activate the environment in a terminal and then run the above command? The reason I believe this is a
condaissue is because we don't compute the environment path for named environments. I believe that something in going on withrunwhen it is run from an already activated environment.related mamba-org/mamba#1467
tbenthompson commentedon Feb 10, 2022
Thanks for thinking about this!
Here, I'm running the exact test discovery command first from the internal VSCode terminal, both with the base environment activated and then with the relevant environment activated. And then, in the second block, I run both commands again from an external terminal (mac, kitty, zsh). In both situations, the commands run without error. Whereas when run from the pytest test discovery tool, the command fails with the error from the original issue post. This is why I lean towards thinking there's something wrong in the test discovery conda call.
My only theory is that perhaps the test discovery is running in a different shell and hasn't had the shell code that gets added by
conda init? I have no idea why that would result in the doubling of the environment path in relation to the conda root directory. I'll investigate this possibility a little bit.VSCode built-in terminal:
External terminal:
pytest test discovery:
tbenthompson commentedon Feb 10, 2022
Ok, this is solved for me. The only thing I changed is that I cleared the
python.condaPathsetting. And the error went away. But that setting was absolutely correct and I don't have any other conda installations on my system, so I'm still confused. But, I'm now happy and confused. Based on the upvotes and other comments, I would prefer not to close the issue since it's clear others are also seeing these errors.karthiknadig commentedon Feb 10, 2022
Ben Thompson (@tbenthompson) This is strange, and thanks for digging into it. Can you share what you had for
python.condaPath? Does it have any unicode characters in the path?tbenthompson commentedon Feb 10, 2022
I had
python.condaPathas/Users/tbent/.mambaforge/bin/conda. There aren't any unicode characters.Also, this is hilarious. I tried setting
python.condaPathagain to the above path in order to see if I could reproduce the error. I can reproduce the error. But, now when I clear the setting again, it does not resolve. So, I'm back to where I started with a screwed up pytest + vscode integration. I also tried out seven other active environments and three of those work fine and four fail. I don't see a useful pattern though!karthiknadig commentedon Feb 10, 2022
Ben Thompson (@tbenthompson) Can you tell me what you have for this setting?

tbenthompson commentedon Feb 10, 2022
It is unchecked. If I check it doesn't change any of the previously discussed behavior.
cswartzvi commentedon Feb 10, 2022
This might not be directly related, but I am able to trigger the same error as Ben Thompson (@tbenthompson) in the pytest test discovery if both the following conditions are met:
Steps to reproduce:
conda create -n vscode-conda-repro python=3.9 pytestvscode-conda-reproenvironment activatedvscode-conda-reprointerpreterconda install -n vscode-conda-repro condaand restart vscodeconda uninstall -n vscode-conda-repro condaand restart vscodeSome notes:
vscode-conda-reproand launch vscode from the command line (code .) the error goes awaypython.condaPathto the correct conda path the error goes awayv2021.12.1559732655the error goes awayvscode-conda-reproenvironmentPerhaps 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.
tbenthompson commentedon Feb 10, 2022
Charles Swartz (@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.
karthiknadig commentedon Feb 10, 2022
Charles Swartz (@cswartzvi) Ben Thompson (@tbenthompson) Thanks for the investigation and patience. We will discuss this internally and update on this.
vancleve commentedon Mar 29, 2022
this is the conda issue:
conda/conda#11174
it seems pretty serious from the point of view of using
conda runin vscode...its certainly causing my vscode-python extension to run the wrong python versiontbenthompson commentedon Mar 30, 2022
Just wanted to update the thread that I've run into this problem again. After I remembered that I'd dealt with it a few weeks ago, I was able to solve it the same way again: uninstall conda from the environment. This is a bit unfortunate and annoying because there are common use cases and real benefits to having conda installed in an environment.
lneisenman commentedon Apr 6, 2022
I'm setting up VSCode on a new computer and I think I am having a similar problem with pytest test discovery. I'm developing a package in a Conda environment called
seegthat includes pytest. When I run the test discovery, I get an error indicating that pytest was not found. Looking at the output, it seems that the error occurs with a command that starts withconda run pythoninstead ofconda run -n seeg pythonso the wrong python is being called.Version: 1.66.0 (user setup)
Commit: e18005f0f1b33c29e81d732535d8c0e47cafb0b5
Date: 2022-03-30T05:50:14.623Z
Electron: 17.2.0
Chromium: 98.0.4758.109
Node.js: 16.13.0
V8: 9.8.177.11-electron.0
OS: Windows_NT x64 10.0.19042
Here is the output from the discovery:
conda run -n seeg --no-capture-output --live-stream python ~.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\get_output_via_markers.py ~.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear
cwd: .
[ERROR 2022-3-6 12:3:27.775]: Error discovering pytest tests:
[r [Error]: Traceback (most recent call last):
File "c:\Users\leisenman.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\get_output_via_markers.py", line 26, in
runpy.run_path(module, run_name="main")
File "C:\Users\leisenman\Miniconda3\lib\runpy.py", line 269, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\leisenman\Miniconda3\lib\runpy.py", line 96, in _run_module_code
run_code(code, mod_globals, init_globals,
File "C:\Users\leisenman\Miniconda3\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "c:\Users\leisenman.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\testing_tools\run_adapter.py", line 17, in
from testing_tools.adapter.main import parse_args, main
File "c:\Users\leisenman.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\testing_tools\adapter_main.py", line 9, in
from . import pytest, report
File "c:\Users\leisenman.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\testing_tools\adapter\pytest_init.py", line 7, in
from ._discovery import discover
File "c:\Users\leisenman.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 8, in
import pytest
ModuleNotFoundError: No module named 'pytest'
ERROR conda.cli.main_run:execute(41):
conda run python c:\Users\leisenman\.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\get_output_via_markers.py c:\Users\leisenman\.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir c:\Users\leisenman\Documents\Python\seeg -s --cache-clearfailed. (See above for error)karthiknadig commentedon Sep 15, 2022
Looks like this is addressed in
conda, conda/conda#11174.The fix is available in the canary version of conda.
We plan on continuing with
conda runfor running tests.xarpy commentedon Sep 24, 2022
Hi guys, Karthik Nadig (@karthiknadig), I tried this solution but it didn't work for me. What ended up solving it, was to perform the installation of an earlier version of the ms-python package, it being version v2022.2.1924087327. But even so, I still can't run any more tests with plugin Test Explorer UI only in terminal by command line,now with the previous version package for ms-python I can run only the debug mode.
Because of this, I created a new issue, related to this, for a newer version to try to understand the problem! First of all, I use vscode on linux, in the version described in the issue.
karrtikr commentedon Nov 9, 2022
Created a bug on conda: conda/conda#12082, feel free to upvote that to raise priority. Closing in favor of conda.