Skip to content

Do not use the old Python terminals to execute when interpreter changes #20018

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

Closed
Leon5x opened this issue Oct 17, 2022 · 4 comments
Closed

Do not use the old Python terminals to execute when interpreter changes #20018

Leon5x opened this issue Oct 17, 2022 · 4 comments
Labels
area-debugging area-terminal feature-request Request for new features or functionality needs PR Ready to be worked on

Comments

@Leon5x
Copy link

Leon5x commented Oct 17, 2022

Type: Bug

Behaviour

Expected vs. Actual

I am switching between different conda environments to test my code with different libraries / library versions.
I change the interpreter at workspace level to a different conda environment. The code seems to work fine the only issue is:
The terminal in which the code is executed still uses the old conda environment (showing the "(oldenv) user@pc:" prompt).
But the code runs fine in the new environment.
This is particular annoying because at first my thought was that the environment didn't change.
It also weird when checking in which environment the code was run.

Killing the terminal and executing the script again activates the correct environment.

It seems the solution could be running "conda activate currentenv" everytime when running/debugging another program, or on switching the current interpreter.

Steps to reproduce:

  1. Create two conda environments. (eg install different versions of the same package)
  2. Start the code with one environment. (eg just output the package version)
  3. Change the interpreter to the second environment.
  4. Start the code again. The terminal still shows the old environment, despite executing with the new environment.

Screenshot from 2022-10-17 13-02-31_

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.6
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Experiment 'pythonSurveyNotification' is active
LSP Notebooks experiment is enabled
LSP Notebooks interactive window support is enabled
> conda info --json
Python interpreter path: ~/miniconda3/envs/ma/bin/python
> /bin/python3 ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/interpreterInfo.py
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/interpreterInfo.py
> conda run -n ma --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
> ~/miniconda3/bin/python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/interpreterInfo.py
> ~/miniconda3/envs/ma/bin/python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/interpreterInfo.py
Starting Pylance language server.
> conda run -n ma --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
> conda run -n ma --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
> conda run -n ma --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
Starting Pylance language server.
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
> conda info --json
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
> conda info --json
> conda info --json
> ~/miniconda3/envs/tvconda/bin/python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/interpreterInfo.py
> conda info --json
> ~/miniconda3/envs/tvpip/bin/python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/interpreterInfo.py
> conda run -n ma --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
DAP Server launched with command: /home/leon/miniconda3/envs/ma/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
> conda info --json
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
> conda run -n ma --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
> conda run -n ma --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
> conda run -n ma --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
Python interpreter path: /usr/bin/python3
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
Python interpreter path: ~/miniconda3/envs/tvconda/bin/python
> conda run -n tvconda --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
> conda info --json
DAP Server launched with command: /home/leon/miniconda3/envs/tvconda/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
> conda info --json
DAP Server launched with command: /home/leon/miniconda3/envs/tvconda/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/tvconda/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
Python interpreter path: ~/miniconda3/envs/tvpip/bin/python
> conda run -n tvpip --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/printEnvVariables.py
Jupyter provided interpreter path override: /home/leon/miniconda3/envs/ma/bin/python
> conda info --json
DAP Server launched with command: /home/leon/miniconda3/envs/tvpip/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
DAP Server launched with command: /home/leon/miniconda3/envs/tvpip/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter
> conda info --json
DAP Server launched with command: /home/leon/miniconda3/envs/tvpip/bin/python /home/leon/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter

User Settings

Multiroot scenario, following user settings may not apply:

languageServer: "Pylance"

Extension version: 2022.16.1
VS Code version: Code 1.72.2 (d045a5eda657f4d7b676dedbfa7aab8207f8a075, 2022-10-12T22:16:26.920Z)
OS version: Linux x64 5.15.0-50-generic
Modes:
Sandboxed: No

A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
i497e931:30553904
pyindex848:30577860
nodejswelcome1cf:30587006
40g7c324:30573242

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Oct 17, 2022
@karrtikr karrtikr added the area-environments Features relating to handling interpreter environments label Oct 17, 2022
@karrtikr
Copy link

@Leon5x Try setting"python.terminal.activateEnvInCurrentTerminal" to true, we do not auto-activate the terminal in focus right now. Feel free leave your feedback here: #19610.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2022
@Leon5x
Copy link
Author

Leon5x commented Oct 18, 2022

This unfortunately doesn't solve the problem.
It seems I didn't explain it properly, sorry:
When I run my code using the default Run->Start Debugging / Run Without Debugging
VS Code opens a "Python Cebug Console" under the Terminal in the Panel. And in this debug console the conda environment is not changed.
Screenshot from 2022-10-18 12-18-03

@karrtikr karrtikr reopened this Oct 18, 2022
@karrtikr
Copy link

karrtikr commented Nov 9, 2022

Thanks I see the issue. With #11039 we'll do a better job of highlighting that a user needs to open a new terminal when environment changes.

Particularly in case of executing and debugging, I'll leave this issue to open to investigate if we can open a new Python and Python Debug Console when an environment changes, instead of reusing existing one.

@karrtikr karrtikr changed the title VSCode terminal shows wrong conda environment on interpreter change Do not use the old Python terminals to execute when interpreter changes Nov 9, 2022
@karrtikr karrtikr removed their assignment Nov 9, 2022
@karrtikr karrtikr added feature-request Request for new features or functionality area-debugging area-terminal needs PR Ready to be worked on and removed triage-needed Needs assignment to the proper sub-team area-environments Features relating to handling interpreter environments labels Nov 9, 2022
@karrtikr
Copy link

Closing as dup of #4581.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging area-terminal feature-request Request for new features or functionality needs PR Ready to be worked on
Projects
None yet
Development

No branches or pull requests

2 participants