0

I have a Python script open in VSC. I have a venv (Python 3.10.0) selected as the Kernel. In terminal I have the following line:

PS C:\Users\person123\Desktop\Project\venv>

I think my venv is not activated. Am I correct and how to activate it? The instruction tricks I've seen (for example this venv\Scripts\activate) don't activate this venv. Thanks for your assistance.

Gato
  • 389
  • 2
  • 12
  • 4
    If youn have active the Python extension by microsoft, simply select the interpreter using the CTRL+shift+p shortcut (open the command palette) and selecting the "python: select interpreter" command. You should see your path already there, otherwise there is a select button so you can indicate your full path – Andrea Pollini Jul 10 '23 at 12:34
  • select the interpreter in the venv, close all terminals, start a launch config and VSC will open a terminal and activate the venv – rioV8 Jul 10 '23 at 12:41
  • @rioV8 what does "start a launch config" mean? – Gato Jul 10 '23 at 12:59
  • have you read the VSC doc pages about debugging – rioV8 Jul 10 '23 at 15:22
  • What Andrea says. Funny thing that may not be apparent - it wasnt to me - is that picking the Python executable, *in its location in the venv*, is more or less equivalent to running activate script. – JL Peyret Jul 10 '23 at 17:21
  • 1
    Selecting an interpreter in vscode, it will be automatically activated. – MingJie-MSFT Jul 11 '23 at 01:24

2 Answers2

1

Selecting an interpreter by shortcuts "Ctrl+Shift+P" and type "Python: Select Interpreter" in vscode, environment will be automatically activated when you run the python script.

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13
0

Looks like you are using powershell. To activate your venv, you should run the activate.ps1 script:

.\venv\Scripts\activate.ps1

And to check if it is properly activated, check the path of your python executable:

(Get-Command python).Path

It should point to your python venv.

matleg
  • 618
  • 4
  • 11
  • ```.\venv\Scripts\activate.ps1``` did not activate it :( – Gato Jul 10 '23 at 13:22
  • Have you run also the command suggested by the first comment of this post: https://stackoverflow.com/a/10030999/13339621 – matleg Jul 10 '23 at 13:26
  • 1
    since you are in the venv folder already try `.\Scripts\activate.ps1` – JonSG Jul 10 '23 at 13:47
  • @matleg yes I tried it but I didn't even understand what was the purpose of seeing the path, and I'm not sure if this ```.\Scripts\python.exe``` is the path. I don't see any "select button" either – Gato Jul 10 '23 at 14:46
  • Thanks @JonSG but that didn't activate it – Gato Jul 10 '23 at 14:47
  • 1
    The point is that if the printed path is the one to your venv, in your case: C:\Users\person123\Desktop\Project\venv\Scripts\python.exe , it means your venv is activated. – matleg Jul 10 '23 at 14:54