-1

What happens when you activate a virtual environment named Foldenv in the terminal of python vscode and then use a virtual environment named venv in the palette?

enter image description here

i enter print ("hello world") in venv interpreter but terminal show me (Foldenv) in front of hello world

rioV8
  • 24,506
  • 3
  • 32
  • 49
Sein kim
  • 25
  • 4
  • kill the terminal, when you run your Python script a terminal will be opened and the `venv` environment will be activated – rioV8 Dec 02 '22 at 19:53
  • If an interpreter named venv and a terminal running a virtual environment named Foldenv are prepared, if I execute "hello world", is it normal that the output is displayed in the virtual environment named Foldenv? – Sein kim Dec 03 '22 at 17:09
  • VSC does not know which virt env is active, if there is a terminal it uses the terminal as is, if no terminal active it creates one and activates the selected virt env – rioV8 Dec 03 '22 at 17:28

1 Answers1

1

Python will use the python interpreter in the lower right corner (the one you selected in the Select Interpreter panel) to run the code.

But it doesn't activate another virtual environment again when there is already a terminal and activate a virtual environment. Unless you close the current terminal and run the code.

enter image description here

Another thing to note is that when you use the button to execute code in a terminal, then this terminal will always exist as the terminal for executing code. The following two cases are examples for your understanding.

The first case

Select the Foldenv environment interpreter and activate the environment in the terminal. Note that no code is running at this time.

enter image description here

Switch the interpreter to .venv in the Select Interpreter panel, Use the play button to execute the code. At this time, a new terminal will be created automatically and the .venv environment will be activated to run the code.

enter image description here

The second case

Select the Foldenv environment interpreter and execute the code directly. A terminal is automatically created and the environment is activated at this point.

enter image description here

Switch the interpreter to .venv and run the code again. At this time, the code will be executed directly in the current terminal, but the .venv environment interpreter will be used.

enter image description here

JialeDu
  • 6,021
  • 2
  • 5
  • 24