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

VS Code can't find Homebrew-installed Conda #23162

Open
1 of 2 tasks
kxmh42 opened this issue Apr 1, 2024 · 7 comments · Fixed by #23171
Open
1 of 2 tasks

VS Code can't find Homebrew-installed Conda #23162

kxmh42 opened this issue Apr 1, 2024 · 7 comments · Fixed by #23171
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on

Comments

@kxmh42
Copy link

kxmh42 commented Apr 1, 2024

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

  1. On macOS 14.3.1, install Conda with brew install miniconda
  2. Open VS Code and open any ipynb file.
  3. Press Shift-Cmd-P and click on "Notebook: Select Notebook Kernel"
  4. Click "Select Another Kernel..."
  5. Click "Python Environments..."
  6. Click "+ Create Python Environment"
  7. Click "Conda"

Expected result: A menu with a choice of the version of Python to install in the environment.
Actual result: An error box in the bottom right corner, saying Install `conda` to create conda environments.

Probable root cause: the hardcoded glob patterns for searching Conda in src/test/interpreters/condaService.node.ts, which don't match /opt/homebrew/bin/conda.

Quick workaround: cd /opt && sudo ln -s homebrew conda (since /opt/conda/bin/conda is matched by the patterns).

A quick solution would be to add a pattern for Homebrew, and a better one would be to look for Conda in a way that is independent of the way it is installed.

VS Code Version

Version: 1.87.2 Commit: 863d2581ecda6849923a2118d93a088b0745d9d6 Date: 2024-03-08T15:20:57.520Z (3 wks ago) Electron: 27.3.2 ElectronBuildId: 26836302 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Darwin arm64 23.3.0

Jupyter Extension Version

v2024.2.0

Jupyter logs

No response

Coding Language and Runtime Version

No response

Language Extension Version (if applicable)

No response

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Local

@kxmh42 kxmh42 added the bug Issue identified by VS Code Team member as probable bug label Apr 1, 2024
@DonJayamanne DonJayamanne removed their assignment Apr 1, 2024
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-jupyter Apr 1, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Apr 1, 2024
@karthiknadig karthiknadig self-assigned this Apr 2, 2024
@karthiknadig karthiknadig added this to the April 2024 milestone Apr 3, 2024
@karthiknadig karthiknadig added area-environments Features relating to handling interpreter environments author-verification-requested Issues potentially verifiable by issue author needs PR Ready to be worked on and removed triage-needed Needs assignment to the proper sub-team labels Apr 3, 2024
@connor4312 connor4312 added the verified Verification succeeded label Apr 24, 2024
@kxmh42
Copy link
Author

kxmh42 commented Apr 26, 2024

I tested it with v2024.5.11021008 (pre-release), and it still doesn't work.

@karthiknadig
Copy link
Member

@kxmh42 You can see here that we specifically look at /opt/homebrew/bin

prefixes.push('/usr/share', '/usr/local/share', '/opt', '/opt/homebrew/bin');

The latest version of the extension is: 2024.5.11172159 and you will need latest VS Code insiders to install the latest python extension insiders.

@kxmh42
Copy link
Author

kxmh42 commented May 5, 2024

I updated to v2024.7.11241010 and can see the above prefixes.push call is present in the compiled code in .vscode/extensions/ms-python.python-2024.7.11241010/out/client/extension.js. However, the bug can still be reproduced with the exactly same steps as above – it cannot find Conda.

@karthiknadig
Copy link
Member

Can you provide logs (Output > Python)again with the latest extension? Make sure you have VS Code version 1.89, and the python extension version 2024.6.0 or greater.

@karthiknadig karthiknadig reopened this May 5, 2024
@kxmh42
Copy link
Author

kxmh42 commented May 6, 2024

VS Code v. 1.89.0, Python extension v2024.7.11241010

2024-05-06 15:44:14.928 [info] Telemetry level is off
2024-05-06 15:44:14.928 [info] Experiments are disabled, only manually opted experiments are active.
2024-05-06 15:44:15.010 [info] Default formatter is set to null for workspace /Users/kaxia/proj/new
2024-05-06 15:44:15.027 [info] > conda info --json
2024-05-06 15:44:15.029 [info] > hatch env show --json
2024-05-06 15:44:15.030 [info] cwd: .
2024-05-06 15:44:15.039 [info] Python interpreter path: /usr/bin/python3
2024-05-06 15:44:15.270 [info] > pyenv which python
2024-05-06 15:44:15.271 [info] cwd: .
2024-05-06 15:44:15.281 [info] > /opt/homebrew/bin/conda/bin/conda info --json
2024-05-06 15:44:15.281 [info] > /opt/homebrew/bin/conda2solv/bin/conda info --json
2024-05-06 15:44:15.290 [info] > ~/.conda/bin/conda info --json
2024-05-06 15:44:15.291 [info] Found: /usr/bin/python3 --> /usr/bin/python3
2024-05-06 15:44:15.319 [info] > /usr/bin/python3 -I ~/.vscode/extensions/ms-python.python-2024.7.11241010/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.7.11241010/python_files/interpreterInfo.py
2024-05-06 15:44:16.202 [info] Starting Pylance language server.

@kxmh42
Copy link
Author

kxmh42 commented May 6, 2024

See the comment in getCandidatesFromKnownPaths:

// Check common locations. We want to look up "<prefix>/*conda*/<suffix>", where prefix and suffix
// depend on the platform, to account for both Anaconda and Miniconda, and all possible variations.

And the definition of suffix:

const suffix = getOSType() === OSType.Windows ? 'Scripts\\conda.exe' : 'bin/conda';

Adding /opt/homebrew/bin to prefixes is incorrect, because now it is looking for the Conda binary in /opt/homebrew/bin/*conda*/bin/conda, and the correct binary path is /opt/homebrew/bin/conda.

In addition to /opt/homebrew/bin/conda, please also consider looking for Conda binary in ~/.local/bin/conda (that is, path.join(home, '.local', 'bin', 'conda')), as this is where the executable might be if it is installed locally on the user's account. I see the same error as above when I run VS Code remotely on a Linux server with Conda installed just on my account.

@karthiknadig
Copy link
Member

@kxmh42 Thanks for looking into this. I got this wrong when I tried it, I will do a fix soon.

@karthiknadig karthiknadig modified the milestones: April 2024, May 2024 May 9, 2024
@karthiknadig karthiknadig removed author-verification-requested Issues potentially verifiable by issue author verified Verification succeeded labels May 9, 2024
wesm pushed a commit to posit-dev/positron that referenced this issue May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on
Projects
None yet
5 participants