microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.3k stars 1.18k forks source link

Python extension always chooses specific Poetry environment instead of pyenv default #23588

Open slhck opened 3 months ago

slhck commented 3 months ago

Note: I cannot file a bug report through VS Code because I get the error Cannot read properties of undefined (reading 'localeCompare') when clicking the Python: Report Issue… action.

When I open a new Python project in VS Code, I always get the same default interpreter, which is a Poetry environment that I actually only use for a particular project. However, it gets auto-selected for every Python project, even one that I haven't loaded before:

image

I am using:

I have set the following custom setting:

"python.venvPath": "~/.cache/pypoetry/virtualenvs, ~/Library/Caches/pypoetry/virtualenvs",

pyenv global is set to 3.11, so which python in a default shell points to /Users/werner/.pyenv/versions/3.11.7/bin/python3. I would expect VS Code to either pick that one for me, or at least the Homebrew-installed one, but definitely not a random Poetry environment.

I do not want to set a default interpreter manually — it's the automatic selection process that appears to broken here.

Here is the Python output:

2024-06-11 13:44:22.192 [info] Experiment 'pythonCreateEnvOnPipInstall' is active
2024-06-11 13:44:22.192 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-06-11 13:44:22.192 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-06-11 13:44:22.193 [info] Experiment 'pythonTestAdapter' is active
2024-06-11 13:44:22.193 [info] Default formatter is set to charliermarsh.ruff for workspace /Users/werner/Documents/Projects/foo
2024-06-11 13:44:22.193 [info] Python interpreter path: ~/Library/Caches/pypoetry/virtualenvs/distribute-speedtests-TZ9Wh3QD-py3.11/bin/python
2024-06-11 13:44:22.237 [info] > pyenv which python
2024-06-11 13:44:22.237 [info] cwd: .
2024-06-11 13:44:22.423 [info] > . ~/Library/Caches/pypoetry/virtualenvs/distribute-speedtests-TZ9Wh3QD-py3.11/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.8.0/python_files/printEnvVariables.py
2024-06-11 13:44:22.423 [info] shell: zsh
2024-06-11 13:44:22.498 [info] > /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2024.8.0/python_files/printEnvVariables.py
2024-06-11 13:44:22.498 [info] shell: zsh
2024-06-11 13:44:22.580 [info] Prepending environment variable PATH in collection with /Users/werner/.vscode/extensions/ms-python.python-2024.8.0/python_files/deactivate/zsh:/Users/werner/Library/Caches/pypoetry/virtualenvs/distribute-speedtests-TZ9Wh3QD-py3.11/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-11 13:44:22.580 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/werner/Library/Caches/pypoetry/virtualenvs/distribute-speedtests-TZ9Wh3QD-py3.11 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-11 13:44:22.580 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to distribute-speedtests-py3.11 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-11 13:44:22.580 [info] Prepending environment variable PS1 in collection with distribute-speedtests-py3.11 {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-06-11 13:44:22.581 [info] Send text to terminal: /usr/bin/python3 /Users/werner/.vscode/extensions/ms-python.python-2024.8.0/python_files/printEnvVariablesToFile.py /Users/werner/.vscode/extensions/ms-python.python-2024.8.0/python_files/deactivate/zsh/envVars.txt
2024-06-11 13:44:23.597 [info] Starting Pylance language server.
anthonykim1 commented 3 months ago

Hi @slhck Thanks for filing this issue. What happens if you do Python: Clear cache and reload this can be triggered via command palette(ctlr/cmd + shift + p) and type in the clear cache...``` I feel like https://github.com/microsoft/vscode-python/issues/23352 may be related.

slhck commented 3 months ago

I haven't yet tried this, but for some reason the problem went away on its own, for now. I will check for the next day or two and reopen the issue if needed.

slhck commented 3 months ago

No, unfortunately, despite clearing the caches, this issue persists.