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

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

Closed
slhck opened this issue Jun 11, 2024 · 6 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@slhck
Copy link

slhck commented Jun 11, 2024

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:

  • Python extension v2024.8.0
  • VS Code Version: 1.90.0, Commit: 89de5a8d4d6205e5b11647eb6a74844ca23d2573
  • macOS 14.5 (23F79)

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.
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jun 11, 2024
@anthonykim1
Copy link

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 #23352 may be related.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jun 20, 2024
@slhck
Copy link
Author

slhck commented Jun 20, 2024

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 slhck closed this as completed Jun 20, 2024
@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Jun 20, 2024
@slhck
Copy link
Author

slhck commented Jun 24, 2024

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

@slhck slhck reopened this Jun 24, 2024
@anthonykim1
Copy link

Are you still experiencing this? @slhck

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Dec 11, 2024
@slhck
Copy link
Author

slhck commented Dec 11, 2024

Unfortunately yes. Is there any specific output/logs I can provide to help troubleshooting this?

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Dec 11, 2024
@slhck
Copy link
Author

slhck commented Dec 11, 2024

Actually, let me close this for now. I did some more tests and I think the only problem I had was when changing directories within the built-in terminal, which obviously loads the wrong Python environment.

@slhck slhck closed this as completed Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants