Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to activate virtual env in vs code?

I can't activate my virtual env in VS Code. I tried same code in the cmd console and it works. But it doesn't work in the VS Code terminal.

This is the command I am trying to run:

D:\python\djangoapp\djangovenv\Scripts\activate.bat

I am using Windows 10 Pro.

like image 308
Sedat Can Avatar asked May 09 '26 18:05

Sedat Can


1 Answers

You need to switch your Python interpreter to point to the one within your venv when you switch the interpreter VS code it create a .vscode folder within your workspace with a settings.json indicating the python interpreter. This will give VS code the direction of where to locate the venv.

You can follow these steps

Step 1: Enter Ctrl+Shift+P in your vs code.

Step 2: Locate your Virtual Environment:

[Select Interpreter]

Python: select interpreter > Enter interpreter path > Find

Step 3: Once you locate your virtual env select your python version:

your-virtual-env > bin > python3.

Step 4 : Now in your project you will see .vscode directory created open settings.json inside of it and add:

"python.terminal.activateEnvironment": true

don't forget to add a comma before to separate it with the already present key-value pair.

Step 5: Now restart the terminal.

Your virtual environment is activated automatically.

like image 138
Ashikur Avatar answered May 12 '26 09:05

Ashikur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!