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

Selecting Python interpreter fails if using Finder (macOS) #22755

Closed
MagnusOxlund opened this issue Jan 17, 2024 · 4 comments
Closed

Selecting Python interpreter fails if using Finder (macOS) #22755

MagnusOxlund opened this issue Jan 17, 2024 · 4 comments
Assignees
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@MagnusOxlund
Copy link

Selecting the Python interpreter through the command palette wizard using Finder fails, whereas entering the interpreter filepath manually works.

Steps to reproduce:

1-7. Using the system terminal (not the built-in VS Code terminal):

mkdir my_project;
cd my_project;
python -m venv venv;
source venv/bin/activate;
pip install flask;
touch app.py;
echo > app.py "from flask import Flask";
  1. Open the project folder (my_project) and app.py in VS Code
  2. Launch the command palette (⇧⌘P)
  3. Type "Python: Select Interpreter"
  4. Click "Enter interpreter path..."
  5. Click "Find..."
  6. Navigate to "my_project/venv/bin/python" and click "Select Interpreter"

Pylance will complain about being unable to find the imported flask module:

Screen Shot 2024-01-17 at 10 49 31 AM

If at step 12, instead of clicking "Find..." the path is entered manually (/path/to/my_project/venv/bin/python), Pylance will recognize the flask module without issue.

Environment data

  • Language Server version: 2023.12.1
  • OS and version: darwin x64
  • Python version (and distribution if applicable, e.g. Anaconda): 3.10.5
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: off
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jan 17, 2024
@karrtikr
Copy link

Duplicate of #22431 (comment), it happens due to a limitation on VS Code's end. Closing in favor of #22431 (comment).

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2024
@MagnusOxlund
Copy link
Author

MagnusOxlund commented Jan 22, 2024

Could I ask you to elaborate on what limitation you're referring to?

#22431 appears to about symlinks. The instructions above don't use the --symlinks flag.

Also, maybe I should point out that the venv folder created using the steps above isn't detected automatically, which is why it's necessary to manually configure the interpreter in the first place.

@MagnusOxlund
Copy link
Author

MagnusOxlund commented Jan 22, 2024

Digging around a bit, this also looks like a duplicate of #13603 (excep for mention of the failure to detect the interpreter automatically).

The upstream issue is vscode #105455 from 2020, which apparently was considered a feature request and closed for lack of interest (and since locked, barring additional upvotes).

I'm curious if the upstream feature is necessary to fix this bug?

It seems like the "Python: Select Interpreter" wizard leads macOS users (for whom --symlinks is the default for venv) to the edge of a cliff. If the issue can't be resolved programatically, maybe it's better to remove the option to use Finder, forcing the user to enter the path manually?

@karrtikr
Copy link

karrtikr commented Jan 22, 2024

Yep, happy to elaborate. So you identified the issue correctly, there are two:

  • VS Code finder always resolves symlinks while selecting a file on macOS, for which they're not willing to provide an option. It works for most binaries except the ones which are symlinks.
  • Python extension fails to automatically detect such interpreters, that is a known issue and should be fixed with Base pyenv versions or virtual envs created using pyenv are missing on macOS #16231, we encourage to upvote that to increase priority.

We're hoping once the second is resolved the first would no longer be needed. Leaving the finder issue as is also helps highlight to VS Code that it's still a problem, which might change their mind about supporting it later.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jan 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants