microsoft / vscode-python

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

Virtual environment from a previous workspace activated in a new workspace that I opened #23352

Open qubitron opened 1 month ago

qubitron commented 1 month ago

Behaviour

The virtual environment of a previous workspace I'm using appears to have somehow been set as the defaultPythonInterpreter

Steps to reproduce:

  1. From the command line, create folder1 and inside of it a virtual environment in it.
  2. Open VS code (code .) in that folder and create a basic "helloworld.py" python script
  3. Now create folder2, and then open vs code (code .) in that folder with a basic helloworld.py

image

Diagnostic data

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

``` 2024-05-06 14:23:23.876 [info] Experiment 'pythonRecommendTensorboardExt' is active 2024-05-06 14:23:23.876 [info] Experiment 'pythonREPLSmartSend' is active 2024-05-06 14:23:23.876 [info] Experiment 'pythonSurveyNotificationcf' is active 2024-05-06 14:23:23.876 [info] Experiment 'pythonTerminalEnvVarActivation' is active 2024-05-06 14:23:23.876 [info] Experiment 'pythonTestAdapter' is active 2024-05-06 14:23:23.876 [info] Default formatter is set to null for workspace c:\dev\bugbash\hubs-and-projects-bugbash 2024-05-06 14:23:23.876 [info] > hatch env show --json 2024-05-06 14:23:23.876 [info] cwd: . 2024-05-06 14:23:23.876 [info] Python interpreter path: c:\dev\promptflow\.venv\Scripts\python.exe 2024-05-06 14:23:23.911 [info] > conda info --json 2024-05-06 14:23:23.981 [info] > c:\dev\promptflow\.venv\Scripts\python.exe -I ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\interpreterInfo.py 2024-05-06 14:23:24.226 [info] > pyenv which python 2024-05-06 14:23:24.226 [info] cwd: . 2024-05-06 14:23:24.370 [info] > c:/dev/promptflow/.venv/Scripts/activate.bat && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/printEnvVariables.py 2024-05-06 14:23:24.370 [info] shell: commandPrompt 2024-05-06 14:23:24.743 [info] > ~\AppData\Local\Programs\Python\Python312\python.exe ~/.vscode/extensions/ms-python.python-2024.6.0/python_files/printEnvVariables.py 2024-05-06 14:23:24.743 [info] shell: commandPrompt 2024-05-06 14:23:24.851 [info] Prepending environment variable PATH in collection with c:\dev\promptflow\.venv\Scripts; {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-06 14:23:24.851 [info] Setting environment variable PROMPT in collection to (.venv) $P$G {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-06 14:23:24.851 [info] Setting environment variable VIRTUAL_ENV in collection to c:\dev\promptflow\.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-06 14:23:24.851 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-06 14:23:24.851 [info] Setting environment variable _OLD_VIRTUAL_PROMPT in collection to $P$G {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-06 14:23:25.561 [info] Starting Pylance language server. 2024-05-06 14:33:14.732 [info] > ~\AppData\Local\Programs\Python\Python312\python.exe -I ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\interpreterInfo.py 2024-05-06 14:33:42.525 [info] > .\.venv\Scripts\python.exe -I ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\interpreterInfo.py 2024-05-06 14:33:49.273 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash 2024-05-06 14:33:49.275 [info] Python interpreter path: .\.venv\Scripts\python.exe 2024-05-06 14:33:50.339 [info] Prepending environment variable PATH in collection with c:\dev\bugbash\hubs-and-projects-bugbash\.venv\Scripts; {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-06 15:14:15.564 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash\create_hub_and_project.py 2024-05-06 15:27:52.650 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash\create_hub_and_project.py 2024-05-06 15:30:58.959 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash\create_hub_and_project.py 2024-05-06 15:34:36.006 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash\create_hub_and_project.py 2024-05-06 15:37:02.606 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash\create_hub_and_project.py 2024-05-06 15:51:31.032 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash\example-hub-and-project-manipulation.py 2024-05-06 15:53:39.131 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash\create_hub_and_project.py 2024-05-06 15:53:53.140 [info] Discover tests for workspace name: hubs-and-projects-bugbash - uri: c:\dev\bugbash\hubs-and-projects-bugbash\create_hub_and_project.py 2024-05-06 16:03:30.288 [info] > .\.venv\Scripts\python.exe -I ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\interpreterInfo.py 2024-05-06 16:03:31.097 [info] > .\.venv\Scripts\python.exe -I ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.6.0\python_files\interpreterInfo.py ```

luabud commented 1 month ago

I can also repro this. I was expecting a global interpreter to be selected by default 🤔 cc @anthonykim1 @karthiknadig

debonte commented 1 month ago

I'm also seeing this. When I go to select a different interpreter, the one I expected to be auto-selected is marked as "Recommended", which I found strange. If that's the recommended one, it should have been selected?

image

sveinse commented 1 month ago

I see the same thing. I use an individual venv per project. If I open two projects at the same time (in two VS Code windows) that each have their own venv/ directory. When I open a new terminal, I get a message that the the venv has been activated. However it incorrectly activates the venv for the project that opened first. In both projects.

It not immediately easy to detect the error as it seems a proper venv has been loaded. But it creates a lot of confusion as pip install will go other places than expected.

debonte commented 1 month ago

If I open two projects at the same time...

I suspect that that is how I was reproing this also.

sveinse commented 1 month ago

Any updates on this?

damienrj commented 1 month ago

This has also been a big issue for us as well.

anthonykim1 commented 1 month ago

Hey folks, apologizes for the late response here. I still cannot repro this. I feel like this might have to do with how we are activating user's Python environment in terminal from our new terminal environment variable activation experiment but am not sure.

Would love to have folks who can repro this consistently try opting out of the experiment and further narrow down the culprit together. Try adding: "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"] to your settings.json and please check to see if you can still repro the problem.

I've created three different workspaces with each different Python virtual environment but have had no luck in repro :/

debonte commented 1 month ago

Try adding: "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"] to your settings.json and please check to see if you can still repro the problem.

It still repros for me with this experiment disabled.