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

native locator does not resolve conda environments in homebrew-installed miniforge #23968

Closed
rzeidler opened this issue Aug 19, 2024 · 10 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug

Comments

@rzeidler
Copy link

rzeidler commented Aug 19, 2024

Type: Bug

Behaviour

The native python locator does not correctly resolve my conda environments from a miniforge installation on MacOS, where miniforge itself was installed via homebrew. The issue occurs on two separate computers, I only discovered the problem because on the newer installation the python extension was set to use the new native locator by default. When using the old js locator everything works as expected.

After trying to select my environment in an interactive python window, the displayed python version in the GUI becomes "Python -1.-1.-1" and an error is reported that the kernel could not be started because the python environment is not available any more.

Steps to reproduce:

  1. Install miniforge in homebrew via brew install miniforge.
  2. Create a conda environment, e.g. mamba create -n test_environ python=3.11
  3. Make sure that the native python locator is selected in the extension settings.
  4. Try to run a python file (or a jupyter notebook) interactively using the created environment.

Judging from the log files, it seems that after these steps, the new locator tries to run /opt/homebrew/bin/python (which does not even exist!), rather than the correct /opt/homebrew/Caskroom/miniforge/base/envs/test_environ/bin/python3.11.

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Python.log

2024-08-19 12:42:09.715 [info] Conda environment manager found at: /opt/homebrew/Caskroom/miniforge/base/bin/conda
2024-08-19 12:42:09.743 [info] Native locator: Refresh finished in 68 ms
2024-08-19 12:42:12.431 [error] Invalid version for /opt/homebrew/Caskroom/miniforge/base/envs/test_environ/bin/python: {"name":"","location":"/opt/homebrew/bin/python","kind":"global-system","id":"/opt/homebrew/bin/python","executable":{"filename":"/opt/homebrew/bin/python","sysPrefix":"","ctime":-1,"mtime":-1},"version":{"sysVersion":null,"major":-1,"minor":-1,"micro":-1},"arch":1,"distro":{"org":""},"source":[],"detailedDisplayName":"Python","display":"Python"}
2024-08-19 12:42:12.450 [error] Invalid version for /opt/homebrew/bin/python: {"name":"","location":"/opt/homebrew/bin/python","kind":"global-system","id":"/opt/homebrew/bin/python","executable":{"filename":"/opt/homebrew/bin/python","sysPrefix":"","ctime":-1,"mtime":-1},"version":{"sysVersion":null,"major":-1,"minor":-1,"micro":-1},"arch":1,"distro":{"org":""},"source":[],"detailedDisplayName":"Python","display":"Python"}
2024-08-19 12:42:12.450 [error] Invalid version for /opt/homebrew/bin/python: {"name":"","location":"/opt/homebrew/bin/python","kind":"global-system","id":"/opt/homebrew/bin/python","executable":{"filename":"/opt/homebrew/bin/python","sysPrefix":"","ctime":-1,"mtime":-1},"version":{"sysVersion":null,"major":-1,"minor":-1,"micro":-1},"arch":1,"distro":{"org":""},"source":[],"detailedDisplayName":"Python","display":"Python"}
2024-08-19 12:42:12.450 [error] Invalid version for /opt/homebrew/bin/python: {"name":"","location":"/opt/homebrew/bin/python","kind":"global-system","id":"/opt/homebrew/bin/python","executable":{"filename":"/opt/homebrew/bin/python","sysPrefix":"","ctime":-1,"mtime":-1},"version":{"sysVersion":null,"major":-1,"minor":-1,"micro":-1},"arch":1,"distro":{"org":""},"source":[],"detailedDisplayName":"Python","display":"Python"}

Python Locator.log

2024-08-19 12:42:12.429 [error] Failed to execute Python to resolve info "/opt/homebrew/bin/python": No such file or directory (os error 2)
2024-08-19 12:42:12.429 [error] Failed to resolve env "/opt/homebrew/Caskroom/miniforge/base/envs/test_environ/bin/python", returning discovered env PythonEnvironment { display_name: None, name: None, executable: Some("/opt/homebrew/bin/python"), kind: Some(Homebrew), version: None, prefix: None, manager: None, project: None, arch: None, symlinks: Some(["/opt/homebrew/Caskroom/miniforge/base/envs/test_environ/bin/python3.11", "/opt/homebrew/bin/python"]) }
2024-08-19 12:42:12.429 [info] Resolved Python Environment /opt/homebrew/bin/python
2024-08-19 12:42:12.450 [error] Failed to execute Python to resolve info "/opt/homebrew/bin/python": No such file or directory (os error 2)
2024-08-19 12:42:12.450 [error] Failed to resolve env "/opt/homebrew/bin/python", returning discovered env PythonEnvironment { display_name: None, name: None, executable: Some("/opt/homebrew/bin/python"), kind: Some(Homebrew), version: None, prefix: None, manager: None, project: None, arch: None, symlinks: Some(["/opt/homebrew/bin/python"]) }
2024-08-19 12:42:12.450 [info] Resolved Python Environment /opt/homebrew/bin/python

Extension version: 2024.12.3
VS Code version: Code 1.92.2 (Universal) (fee1edb8d6d72a0ddff41e5f71a671c23ed924b9, 2024-08-14T17:29:30.058Z)
OS version: Darwin arm64 23.6.0
Modes:

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


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
Black Formatter ms-python.black-formatter 2024.2.0
Code Spell Checker streetsidesoftware.code-spell-checker 3.0.1
CodeLLDB vadimcn.vscode-lldb 1.10.0
Docker ms-azuretools.vscode-docker 1.29.2
Entwicklungscontainer ms-vscode-remote.remote-containers 0.380.0
Even Better TOML tamasfe.even-better-toml 0.19.2
Excel to Markdown table csholmq.excel-to-markdown-table 1.3.0
German - Code Spell Checker streetsidesoftware.code-spell-checker-german 2.3.2
German Language Pack for Visual Studio Code MS-CEINTL.vscode-language-pack-de 1.92.2024081409
GitHub Codespaces GitHub.codespaces 1.17.2
GitHub Copilot GitHub.copilot 1.223.0
GitHub Copilot Chat GitHub.copilot-chat 0.18.2
GitLens — Git supercharged eamodio.gitlens 15.3.0
Go golang.go 0.42.0
Hexadezimal-Editor ms-vscode.hexeditor 1.10.0
isort ms-python.isort 2023.10.1
JavaScript Debugger ms-vscode.js-debug 1.92.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.3
Jupyter ms-toolsai.jupyter 2024.7.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.19
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
LaTeX Workshop James-Yu.latex-workshop 10.1.0
lean4 leanprover.lean4 0.0.176
Markdown Preview Mermaid Support bierner.markdown-mermaid 1.23.1
Pylance ms-python.vscode-pylance 2024.8.1
Pylint ms-python.pylint 2023.10.1
Python ms-python.python 2024.12.3
Python Debugger ms-python.debugpy 2024.10.0
Remote - SSH ms-vscode-remote.remote-ssh 0.113.1
Remote - SSH: Editing Configuration Files ms-vscode-remote.remote-ssh-edit 0.86.0
Remote - Tunnels ms-vscode.remote-server 1.5.2
Remote-Explorer ms-vscode.remote-explorer 0.4.3
rust-analyzer rust-lang.rust-analyzer 0.3.2078
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
Word Count ms-vscode.wordcount 0.1.0
System Info
Item Value
CPUs Apple M2 (8 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 2, 2, 3
Memory (System) 16.00GB (0.19GB free)
Process Argv --crash-reporter-id d0b91948-e635-44b9-81c3-673cf98b8612
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
vscaac:30438847
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
pythonnoceb:30805159
asynctok:30898717
pythonregdiag2:30936856
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
f3je6385:31013174
pythoncenvpt:31062603
a69g1124:31058053
dvdeprecation:31068756
dwnewjupytercf:31046870
impr_priority:31102340
refactort:31108082
pythonrstrctxt:31112756
flightc:31119335
wkspc-onlycs-c:31111717
wkspc-ranged-c:31118571

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Aug 19, 2024
@corneliusroemer
Copy link

corneliusroemer commented Aug 19, 2024

Duplicate of Similar to #23963 #23922

This seems to be an issue faced by very many people, which is confirmed by the high number of views of the stackoverflow question I created: https://stackoverflow.com/a/78886126/7483211

TL;DR:

Add this to your user settings:

"python.locator": "js",

@rzeidler
Copy link
Author

rzeidler commented Aug 19, 2024

Not completely sure this is the same issue as the ones you linked. Certainly looks similar, but in my case the python extension starts up fine (e.g. syntax highlighting works). I can even use the global brew python. Just activating any of the conda environments fails. Of course it could still be the same issue and the difference in behavior is caused by other aspects of my configuration.

In any case, switching to the js locator does fix the problem, so it is certain an issue related to the native locator.

@corneliusroemer
Copy link

Thanks, that's helpful context! Might be one root cause with different symptoms/manifestations depending on the venvs/conda/pixi/poetry environments one has present.

@anthonykim1 anthonykim1 added bug Issue identified by VS Code Team member as probable bug area-environments Features relating to handling interpreter environments and removed triage-needed Needs assignment to the proper sub-team labels Aug 19, 2024
@DonJayamanne
Copy link

DonJayamanne commented Aug 20, 2024

@rzeidler @austinmw @corneliusroemer Please can you try installing the pre-release version and checking if that works.

If this doesn't work, please try the following:

  • Select the command Python: Clear Cache and Reload Window
  • Exit VS Code
  • Open VS Code
  • Set the trace level to Trace by selecting the command Developer: Set Log Level and select Trace
  • Reproduce the problem
  • Share the logs from the Python and Python Locator output panels
    use the command Python: Show Output to get to the Python output, then select Python Locator)
  • Please share screenshots of any other problems/errors you see (in VS Code)

I have tested this at my end and it works for me.

@DonJayamanne

This comment has been minimized.

@corneliusroemer
Copy link

Thanks @DonJayamanne - I confirm the problem is fixed for me, even when changing the locator back to native. (I always use pre-release: v2024.13.2024081501 (pre-release))

@toby-coleman
Copy link

Thank you @DonJayamanne - I can also confirm that this is fixed in the pre-release version.

@rzeidler
Copy link
Author

rzeidler commented Aug 20, 2024

Thanks @DonJayamanne – for me it also seems to be fixed in the pre-release version.

@DonJayamanne
Copy link

Closing as fixed
The next stake version of the extension will contain the fix

@corneliusroemer
Copy link

The issue has unfortunately come back in the newer prerelease version v2024.13.2024082001 (pre-release)

See #23982 - the "python.locator": "js", settings workaround still works though, so that's good!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

6 participants