Repository navigation
Prefix conda environment gets run by name instead of path #24627
Copy link
Copy link
Closed
Labels
bugIssue 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
Discussed in #24626
Originally posted by gandhis1 December 17, 2024
In version 2024.16.1, when I run test discovery, or really any command that ultimately invokes conda, I see the following:
2024-12-17 10:09:14.508 [info] > conda run -p ./envs/linux_main --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2024.16.1-linux-x64/python_files/get_output_via_markers.py -m pytest -p vscode_pytest --collect-only .
This works, and this is what I expect, since my environments are nameless and path-based. Here is the anonymized output of conda info --env:
/home/myuser/git/myrepo/envs/linux_arctic
/home/myuser/git/myrepo/envs/linux_main
base * /opt/miniconda3
In recent versions (this has been ongoing for several weeks I believe), I see this (2024.23.2024121701):
2024-12-17 10:32:03.637 [info] > ~/git/myrepo2/envs/linux_py38/bin/conda run -n linux_main --no-capture-output python ~/.vscode-server/extensions/ms-python.python-2024.23.2024121701-linux-x64/python_files/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2024.23.2024121701-linux-x64/python_files/printEnvVariables.py
2024-12-17 10:32:03.637 [info] shell: bash
2024-12-17 10:32:04.012 [error] getActivatedEnvironmentVariables Error: Command failed: /home/myuser/git/myrepo/envs/linux_py38/bin/conda run -n linux_main --no-capture-output python /home/myuser/.vscode-server/extensions/ms-python.python-2024.23.2024121701-linux-x64/python_files/get_output_via_markers.py /home/myuser/.vscode-server/extensions/ms-python.python-2024.23.2024121701-linux-x64/python_files/printEnvVariables.py
EnvironmentLocationNotFound: Not a conda environment: /home/myuser/git/myrepo/envs/239fb791f5e1df62ec6015e65582c32020a01c5d/envs/linux_main
at genericNodeError (node:internal/errors:984:15)
at wrappedFn (node:internal/errors:538:14)
at ChildProcess.exithandler (node:child_process:422:12)
at ChildProcess.emit (node:events:530:35)
at maybeClose (node:internal/child_process:1104:16)
at Socket.<anonymous> (node:internal/child_process:456:11)
at Socket.emit (node:events:518:28)
at Pipe.<anonymous> (node:net:343:12) {
code: 1,
killed: false,
signal: null,
cmd: '/home/myuser/git/myrepo2/envs/linux_py38/bin/conda run -n linux_main --no-capture-output python /home/myuser/.vscode-server/extensions/ms-python.python-2024.23.2024121701-linux-x64/python_files/get_output_via_markers.py /home/myuser/.vscode-server/extensions/ms-python.python-2024.23.2024121701-linux-x64/python_files/printEnvVariables.py'
}
Fundamentally, the issue I see is that this should be using -p and not -n. It's also using a somewhat arbitrary conda executable.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugIssue 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
karthiknadig commentedon Dec 17, 2024
Siddhartha Gandhi (@gandhis1) Can you provide the initial part of the logs:

The logs that you shared here don't contain a line that says " Conda env is named/prefix". it comes from the detector.
#24626 (reply in thread)
gandhis1 commentedon Dec 17, 2024
Here is everything before "discover tests":
I don't see a line saying "Conda env is named"
karthiknadig commentedon Dec 17, 2024
Can you
~/git/myrepo2/envs/linux_py38/bin/conda info --json? That seems like your in project conda binary, as opposed to runningconda info --jsonthat uses your global conda binary.gandhis1 commentedon Dec 17, 2024
Here is the output of that. As a clarification, note that
linux_py38,linux_main, etc. are symbolic links to an environment using a hash as the name.karthiknadig commentedon Dec 18, 2024
Siddhartha Gandhi (@gandhis1) Can you try setting
python.condaPathsetting in your user settings? Just so it prevents python extension for seeing other conda that it probably should not.leeleavitt commentedon Dec 19, 2024
On version it runs this command,
conda run -p ./.venv --no-capture-output python ~/.vscode/extensions/ms-python.python-2024.4.1/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.4.1/python_files/printEnvVariables.pyOn the new one it runs this command,
conda run -n .venv --no-capture-output python ~/.vscode/extensions/ms-python.python-2024.22.0-darwin-arm64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-darwin-arm64/python_files/printEnvVariables.pygandhis1 commentedon Dec 30, 2024
Do you need any more information to replicate the issue? I think replication could be as simple as creating a path-based, anonymous conda environment, and then attempting to use it as the interpreter in VS code.
aicd0 commentedon Jan 4, 2025
Same issues here, anyone looking into this?
[-]Nameless conda environment gets run by name instead of path[/-][+]Prefix conda environment gets run by name instead of path[/+]Restrict conda binary to be from PATH or Settings (microsoft#24709)
gandhis1 commentedon Jan 10, 2025
So the attached PR appears to restore the original behavior as for which
condaexecutable gets used, but did you confirm that was the root cause of VS code referencing an anonymous conda environment with a-ppath parameter and not a-nname parameter? If the latter issue isn't fixed I suspect the problem I reported here won't be either.karthiknadig commentedon Jan 11, 2025
The environments dirs returned when using
condathat was not on path led to wrong checks when trying to determine if a environment was prefix or not. In cases wherecondawas using -n for -p, was because we were using wrongcondaand it would tell us that the dir where the.condaenv was is a default environments dir. Causing us to treat it as a named environment.karthiknadig commentedon Jan 11, 2025
There is also another issue that
petis reporting multiplebaseenvironments.microsoft/python-environment-tools#184
A workaround for that is remove
condainstalled in the environment, typically you don't need to have those, since there is already a global conda available.Restrict conda binary to be from PATH or Settings (microsoft#24709)
Always use environment path when running conda environment commands (#…