194

In my project folder I created a venv folder:

python -m venv venv

When I run command select python interpreter in Visual Studio Code, my venv folder is not shown. I went one level up like suggested here, but Visual Studio Code doesn't see my virtual interpreter.

What did I miss?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hrvoje T
  • 3,365
  • 4
  • 28
  • 41
  • 3
    This is the most basic but most thorough tutorial: https://code.visualstudio.com/docs/python/python-tutorial#_install-and-use-packages – JustBeingHelpful Jan 27 '21 at 16:00
  • The issue is you're using a Microsoft product. I opened git-bash and typed "python -m venv venv" then "source venv/scripts/activate". Why is it so difficult to achieve in VSCode... – ron_g Jul 27 '23 at 12:35

26 Answers26

209

P.S.:

  • I have been using Visual Studio Code for a while now and found an another way to show virtual environments in Visual Studio Code.

  • Go to the parent folder in which venv is there through a command prompt.

  • Type code . and Enter. [It is working on both Windows and Linux for me.]

  • That should also show the virtual environments present in that folder.

Original Answer

I almost run into same problem every time I am working on Visual Studio Code using venv. I follow the below steps:

  1. Go to menu FilePreferencesSettings.

  2. Click on Workspace settings.

  3. Under Files:Association, in the JSON: Schemas section, you will find Edit in settings.json. Click on that.

  4. Update "python.defaultInterpreterPath": "Your_venv_path/bin/python" under workspace settings. (For Windows): Update "python.defaultInterpreterPath": "Your_venv_path\Scripts\python.exe" under workspace settings.

  5. Restart Visual Studio Code in case if it still doesn't show your venv.

Note: Use python.pythonPath instead of python.defaultInterpreterPath for older versions.

fnkr
  • 9,428
  • 6
  • 54
  • 61
Sumit S Chawla
  • 3,180
  • 1
  • 14
  • 33
  • My venv file has `Include, Lib and Scripts` folders. I updated `settings.json`, but no luck `"python.pythonPath": "PrintPython\\venv\\Scripts\\python"`. `PrintPython` is my project file inside Python workspace. `venv` folder is in `PrintPython`. – Hrvoje T Jan 09 '19 at 09:52
  • 1
    @HrvojeT; You have to follow these steps in VSCode. – Sumit S Chawla Jan 09 '19 at 09:54
  • Sure, I followed them. No luck. – Hrvoje T Jan 09 '19 at 09:55
  • I guess you are using Windows. For windows use the full path: `"python.pythonPath": "c:/sam/venv/Scripts/python.exe"` or whereever your venv is. Use this link for reference: https://code.visualstudio.com/docs/python/environments – Sumit S Chawla Jan 09 '19 at 10:02
  • 5
    Ok I fugured it out. In one workspace folder named `Python` I added all my other projects. So I would have to have only one venv for workspace folder `Python`. I removed folder `Python` from workspace and added each subfolder in Python folder as a workspace project like `Project1`, `Project2` etc. In that `Project` folder I created `venv` environment and edited `settings.json` for workspace with this `"python.venvPath": "venv"` . Now, for every new project I will create new workspace and inside that folder goes `venv` folder which will be automatically recognized. – Hrvoje T Jan 09 '19 at 10:16
  • @HrvojeT: Great..! I don't know if it is the best solution that you mentioned, but its good if it works for you. – Sumit S Chawla Jan 09 '19 at 10:22
  • I added an answer that is simple and doesnt involve editing any configuration files – The Welsh Dragon Jun 13 '19 at 16:58
  • 2
    Yea, you shouldn't have to go to this much trouble to get VS Code to recognize your virtual environment. The folder is right there in the directory you opened VS Code in. The VS Code team should address this if they truly want to support Python. It can't possibly be that hard. – Jim Jun 18 '19 at 15:56
  • The update should be the main section of the answer imo – Jesse Reza Khorasanee Feb 19 '20 at 04:53
  • 1
    If you're using JSON settings, then check the settings.json file in your workspace. My vscode added `pythonPath` automatically, so when changing it globally it didn't do anything. – Antoni Silvestrovič Feb 19 '20 at 12:09
  • I use `wsl` and put `"pythonpath"` to `"venv/bin/python"` in the `settings.json` project. It does not work with debugging - F5 - it looks for system python. When I do `source venv/bin/activate; python in.py` from terminal it works. – Timo Nov 29 '21 at 20:13
  • Core sentence that I had overseen for some time: `Go to the parent folder in which venv is`. Yes, it is that easy. Works also in Codium (open source vscode). – questionto42 Dec 10 '21 at 23:46
  • I have Vscode 1.64.2 and `python.defaultInterpreterPath` in settings.json worked. I have a settings.json in my project where I put the path and a settings.json in my workspace settings which is for general settings for all projects. – Timo Feb 23 '22 at 13:26
  • It seems that 'code .' launches VS Code in the current directory. And I assume that when done from the terminal, it knows to just relaunch the environment, and not the whole editor. And since neither one of those things loaded my environment, I also assume that the settings modification in the 'original answer' still has to happen. Although it did seem to recognize my module.. was it cached, or did scan the subdirectory? Is there any chance on Stack Overflow I can get the "why"s and "what"s answered? :) – Gerard ONeill Aug 04 '22 at 18:27
  • for me it only worked when i used, the pythonw.exe ` `"python.defaultInterpreterPath": ".\venv\Scripts\pythonw.exe" ` – extreme4all Aug 11 '22 at 08:57
  • @SumitSChawla For `Windows`: should I use "\" OR "/" for the `python.pythonPath` setting ? – Grace Oct 27 '22 at 07:58
  • @Grace It should be \ for windows. Thanks for pointing it out. – Sumit S Chawla Oct 30 '22 at 16:03
164

With a newer Visual Studio Code version it's quite simple.

Open Visual Studio Code in your project's folder.

Then open Python Terminal (Ctrl + Shift + P: Python: Create Terminal)

In the terminal:

python -m venv venv

You'll then see the following dialog:

Enter image description here

Click Yes; and your venv is ready to go.

Open a new terminal within VSCode Ctrl + Shift + P and you'll see that venv is getting picked up; e.g.: (venv) ...

You can now instal packages as usual, e.g., pip install sklearn

To keep track of what is installed: pip freeze > requirements.txt


For the older versions of VSCode you may also need to do the following:

Then Python: Select Interpreter (via Ctrl + Shift + P)

And select the option (in my case towards the bottom)

Python 3.7 (venv) ./venv/Scripts/python.exe

If you see

Activate.ps1 is not digitally signed. You cannot run this script on the current system.

you'll need to do the following: https://stackoverflow.com/a/18713789/2705777

For more information see: Global, virtual, and conda environments

Installing Modules

Ctrl + Shift + P and Terminal: Create New Integrated Terminal

from the terminal

Windows: .\.venv\Scripts\activate

Linux: ./.venv/bin/activate

You can now instal packages as usual, e.g., pip install sklearn.

For Jupyter, you need to do more - Jupyter notebooks in Visual Studio Code does not use the active virtual environment

Aubin
  • 14,617
  • 9
  • 61
  • 84
Neil
  • 7,482
  • 6
  • 50
  • 56
  • 1
    is the "." in front the "venv" require for vsc to automatically recognize the virtual environment folder? I always name mine "venv" ( no leading dot ). Thx. – majorgear Oct 11 '20 at 17:27
  • not sure if '.' is needed for it to be picked up by VSCode p.s. as per python docs `a common name for the target directory is .venv` https://docs.python.org/3/library/venv.html#creating-virtual-environments – Neil Apr 05 '21 at 08:50
  • 2
    Yep, same problem here. I do what the instructions say, the popup never shows. – Etienne de Martel Aug 24 '21 at 17:44
  • I have version 1.62.3 and Ubuntu 20.04 and do not get the dialog after `python -m venv ve` in the VSCode Terminal. – Timo Nov 23 '21 at 20:03
  • 2
    @Timo you must run that in system's terminal, not VSCode Terminal. Just open VSC Terminal and type/select "Python: Create Terminal" to create a terminal tab inside VSC, then you can create the virtual env OR you can just open a terminal in projects path and ready to create – G.Mendes Nov 29 '21 at 12:29
  • After clicking yes on the dialogue, an internal setting is made that starts a new terminal in `venv`. I would like to see this setting in some file in `.vscode` in a project, but probably it is under the hood for a VSCode user. – Timo Feb 24 '22 at 10:56
  • `Terminal: Create New Integrated Terminal` does not exist in VScode 1.65.2 – Timo Apr 01 '22 at 07:13
  • 3
    What if my virtual env already exists? – Myles Prather Jun 01 '22 at 20:51
  • Myles - Not sure if I've done something to my setup, but launching a new terminal picks up my environment by running the activate script. (ctrl-shift-`), or the plus. Unfortunately the environment isn't picked up in the existing terminal when VSCode is started in the directory. The command is in the history though. – Gerard ONeill Aug 04 '22 at 19:37
  • I dont get that dialog – ViktorMS Dec 29 '22 at 16:28
38

If you already have your virtualenvs, you only need to open VSCode preferences (Ctrl + ,) and search for venv. Then add the path of the virtualenvs to the “Venv Path” settings, like so:

enter image description here

More information can be found here: https://techinscribed.com/python-virtual-environment-in-vscode/

I_Al-thamary
  • 3,385
  • 2
  • 24
  • 37
  • 10
    This is the best answer! Changing the interpreter alone to point to the python symlink in the venv picks up the right interpreter, but it could not find the packages installed in the venv. With this solution vs code can find the packages too. – rahulmohan Aug 31 '22 at 18:57
  • 5
    only working solution – Talha Anwar Sep 29 '22 at 08:52
  • 5
    you saved my day! and I created a Youtube video to make it easier for ppl to follow: https://youtu.be/DB5-JiYWMNs – Sky Nov 28 '22 at 16:26
14

I fixed the issue without changing the Python path as that did not seem like the right solution for me. The following solution worked for me, and hopefully it works for you as well :))

  1. Open cmd in Windows / shell in Linux/Mac.

  2. Activate your virtualenv (using source activate / activate.bat / activate.ps1 if using PowerShell)

    C:\Users\<myUserName>\Videos\myFolder>django-project\Scripts\activate.bat (django-project) C:\Users\<myUserName>\Videos\myFolder>

  3. Navigate to your project directory and open Visual Studio Code there.

    (django-project) C:\Users\prash\Videos\myFolder\projects>code .

  4. in Visual Studio Code, go to menu FilePreferencesSettings (don’t worry you don’t need to open the JSON file)

  5. In the setting search bar, search for virtual / venv and hit Enter. You should find the below in the search bar:

Python: Venv Folders Folders in your home directory to look into for virtual environments (supports pyenv, direnv and virtualenvwrapper by default).

  1. Add an item, and then enter the path of the scripts of your virtuanenv which has the activate file in it. For example, in my system, it is:

    C:\Users\<myUserName>\Videos\myFolder\django-project\Scripts\

  2. Save it and restart Visual Studio Code.

  3. To restart, open cmd again, navigate to your project path and open Visual Studio Code. (Note that your venv should be activated in cmd before you open Visual Studio Code from cmd)

Command to open Visual Studio Code from cmd:

code .

How to setup virtualenv in Visual Studio Code

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
12

I was having the same issue until I worked out that I was trying to make my project directory and the virtual environment one and the same - which isn't correct.

I have a \Code\Python directory where I store all my Python projects. My Python 3 installation is on my Path.

If I want to create a new Python project (Project1) with its own virtual environment, then I do this:

python -m venv Code\Python\Project1\venv

Then, simply opening the folder (Project1) in Visual Studio Code ensures that the correct virtual environment is used.

MarredCheese
  • 17,541
  • 8
  • 92
  • 91
The Welsh Dragon
  • 519
  • 1
  • 4
  • 19
  • Using Codium, I still had to change to the venv by clicking the bottom left interpreter status and choose my new venv. – questionto42 Dec 02 '21 at 09:59
11

Steps to create virtual environment:

  1. go to folder containing project
  2. python3 -m venv evn_name
  3. source evn_name/bin/activate
  4. now you will be able to see (env_name) infront of the each terminal line

Now you can install required libraries in virtual environment

  1. pip3 install -r requirement.txt
  2. if needed restart code editor

to stop working in virtual environment type: deactivate

to remove virtual environment type: rm -rf evn_name

ratnesh
  • 436
  • 1
  • 5
  • 16
  • What do you mean with "restart" the terminal? I think when do a `source .bashrc` or `exec bash` which is like a restart then you loose the virtual environment and you have the same result as putting `deactivate`. So you need to change your answer. – Timo Dec 04 '21 at 09:53
  • @Timo in vscode, after activating virtual environment, if you open new terminal, it will open with the virtual environment you created. Anyways, I am removing that statement, it is misleading, sorry for that – ratnesh Dec 05 '21 at 11:28
  • 1
    Restarting VSCode worked! – dev1ce Feb 08 '23 at 12:31
8

For Anaconda users: Just create a venv using Conda, see here. Afterwards, open Visual Studio Code and left-click on the Visual Studio Code interpreter shown in Visual Studio Code at the bottom left:

Visual Studio Code interpreter information

Choose a virtual environment that pops up in a dropdown of the settings window, and you are done.

questionto42
  • 7,175
  • 4
  • 57
  • 90
  • For VSCode it is important that a python interpreter is specified, as stated here: https://code.visualstudio.com/docs/python/environments#_conda-environments – Nicow Mar 18 '21 at 08:12
  • @Nicow Thanks for the official link which supports the answer here (just to make this clear). `To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).` And: `The Status Bar always shows the current interpreter. ... The Status Bar also reflects when no interpreter is selected. ... In either case, clicking this area of the Status Bar is a convenient shortcut for the Python: Select Interpreter command.` Thus, the status bar is the official shortcut to activate the venv. – questionto42 Mar 18 '21 at 11:22
6

This is an addition to Sumit S Chawla's answer that, though it is correct, is missing the fact that anytime you open a folder in Visual Studio Code, it creates a .vscode folder, but those can be multiple, created any time you eventually open a directory.

The .vscode folder has JSON objects that content properties such "setting.json", in which one declare the interpreter to use at that the ".vscode" level (refer to What is a 'workspace' in Visual Studio Code? for more clarifications).

{
   {
     "python.pythonPath": "VirtualEnPath/bin/python3.6"
   }
}

So potentially you could open Visual Studio Code at another level in the virtual environment. It creates another .vscode folder that assume as Python directory those of the global machine and so having such an error, and has I experienced has nothing to do if the virtual environment is activated or not.

This is indeed what happened to me. I have indeed a DjangoRESTAPI_GEN folder in which I initially opened the IDE and it did recognize the virtual environment Python path. Then a few days after I opened it at the level where Git is, so it did create another .vscode folder, that picked the global Python Interpreter, causing my lint in the virtual environment not been used.

And the virtual env interpreter did not even show in "select python interpreter". But as written, opening the IDE at the level where the .vscode folder, that has the settings.json file with the correct path, it does.

Once you set the correct path in the setting.json file and select the virtual environment interpreter, then Visual Studio Code will automatically activate the virtual environment in its terminal:

Enter image description here

Carmine Tambascia
  • 1,628
  • 2
  • 18
  • 32
5

Many have mentioned the python.pythonPath method.

Another way is adding a envFile in the launch.json like this:

    {
        "name": "Run",
        "etc": "etc",
        "envFile": "${workspaceFolder}/venv"
    }
Alex Telon
  • 1,107
  • 1
  • 14
  • 30
  • This is helpful, `${workspaceFolder}` -- literally what I want. Don't think absolute path make sense if you are doing workspace setting for virtual environment, which only applies to the project. – Shawn Dec 19 '19 at 19:13
5

There is a Visual Studio Code extension called "Python Auto Venv" that automatically detects and uses your virtual environment if there is one.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark Kortink
  • 1,770
  • 4
  • 21
  • 36
4

You have to select python that is in the virtual environment

  1. create new venv (virtualenv -p python3 venv)
  2. open directory (with venv) in Vs Code
  3. CMD + Shift + P: Python: Select Interpreter from venv

github

mehdi
  • 2,703
  • 1
  • 13
  • 15
  • I had to manually select the venv path to bin/python from the file system menu in vscode after step three because there was no entry for the venv path. – Timo Apr 01 '22 at 07:23
4

With Visual Studio Code, a task within task.json can be configured to build a python environment with python modules listed in the requirements.txt and upgrade pip within that virtual environment. To create the task, goto Terminal -> Configure Tasks. If there is no task.json existing in your environment, create task.json file from template -> then click other and copy and paste the json below. This task is agnostic to Operating Systems such as Windows, Linux, and MacOS. With Windows' ecosystem of command-line applications, cmd.exe is used in conjunction with the flags /c and /d to ensure that the environment created by the task is correct. As mentioned by Neil in his post, you can either select Yes after the dialog prompt or select the python interpreter via the command palette.

{

    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Python Env",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "linux": {
                "options": {
                    "cwd": "${workspaceFolder}"
                },
                "command": "python3 -m venv py_venv && source py_venv/bin/activate && python3 -m pip install --upgrade pip && python3 -m pip install -r requirements.txt && deactivate py_venv"
            },
            "osx": {
                "options": {
                    "cwd": "${workspaceFolder}"
                },
                "command": "python3 -m venv py_venv && source py_venv/bin/activate && python3 -m pip install --upgrade pip && python3 -m pip install -r requirements.txt && deactivate py_venv"
            },
            "windows": {
                "options": {
                    "shell": {
                        "executable": "C:\\Windows\\system32\\cmd.exe",
                        "args": [
                            "/d",
                            "/c"
                        ]
                    },
                    "cwd": "${workspaceFolder}"
                },
                "command": "(if not exist py_venv py -m venv py_venv) && .\\py_venv\\Scripts\\activate.bat && py -m pip install --upgrade pip && py -m pip install -r requirements.txt && deactivate py_venv"
            },
            "problemMatcher": []
        }
    ]
}

The task labeled Build Python Env is demonstrated to install a Python environment with numpy and pandas indicated as dependencies in requirements.txt example below: enter image description here

If more python packages are added to the requirements.txt, then re-running the task will install the new additional dependencies to the python virtual environment

kyrlon
  • 1,065
  • 2
  • 8
  • 16
  • 3
    Great answer. Also similar, more focused question asked here that this is an answer for - https://stackoverflow.com/questions/75188523/installing-requirements-txt-in-a-venv-inside-vscode. I was gonna flag that as a duplicate but I feel it could be more appropriate as its own question. – Andez Jan 22 '23 at 09:42
  • Thanks for the heads-up. I've created a post in case those searching miss the comments while stumbling across the question. – kyrlon Jan 22 '23 at 15:55
  • This doesn't sound very sane. It seem that it recreates the entire virtual environment, based on what is needed. I think what we need to see is how to use the virtual environments we already have. – not2qubit Jan 25 '23 at 18:29
3

I had the same problem and the solution was pretty easy:

"If you create a new conda environment while VS Code is running, use the Reload Window command to refresh the environment list shown with Python: Select Interpreter; otherwise you may not see the environment there. It might take a short time to appear; if you don't see it at first, wait 15 seconds then try using the command again."

That's written on the Visual Studio Code site.

Note: to reload the window: Ctrl + Shift + P in Visual Studio Code, then write reload window

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rami Ma
  • 966
  • 1
  • 7
  • 13
3
  1. If your using Visual Studio Code on Mac, it's important to have your venv installed in the same directory as your workspace.

  2. In my case my venv was in a different directory (not in my project workspace), so a simple cut/copy-paste of my venv to the project workspace did the trick.

  3. As soon as your venv is copied to the project workspace, your Visual Studio Code will pick that up and show a notification giving you an option to select venv as an interpreter.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Arvind Reddy
  • 406
  • 2
  • 10
2

Let's assume that you have created a virtualenv folder with the name of venv.

You can easily activate it by typing the following command from the directory where venv is installed.

.\venv\Scripts\activate
Praveen Kumar
  • 849
  • 8
  • 8
2

There is a very simple procedure for the new versions of vscode

  1. Open a command pallatte (ctrl+shift+p)
  2. Select "+Enter interpreter path"
  3. Select "Find.." and it will open the file explorer
  4. Go to your eviroiment folder's script folder (ex:C:\Users\name\env\Scripts)
  5. Select the python.exe file
  6. Restart the VScode and if you see the available kernlas you can find your pyhton env there
Jb-99
  • 153
  • 1
  • 10
1

Activate your environment.

You could also try this:

Using Python environments in Visual Studio Code

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Daedalus
  • 295
  • 2
  • 17
  • When I run `activate` in cmd terminal in VS Code it is activated. However I need to change the interpreter in VS Code gui so my imports are recognized. – Hrvoje T Jan 09 '19 at 09:48
1

I had the same problem and it was because PowerShell was not updated. Sometimes Windows preserves version 2.* and I had to manually download and install version 3.

After that, the problem was solved and I could use virtual environments very well.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
julianvare
  • 11
  • 2
1

In Visual Studio Code, select a folder, create a workspace and it will work fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zzfima
  • 1,528
  • 1
  • 14
  • 21
1

For Mac users, note this bug: when you click "Enter interpreter path", you have two options: (1) manually enter the path; (2) select the venv file from Finder.

It only works if I manually enter the path. Selecting with Finder yields some strange path like Library/Developer/CommandTools/... which I understand.

yyFred
  • 775
  • 9
  • 13
1

Two main things I identified that could lead to being unable to see the venv.

  1. If you are using VS Code version 1.60.0 or closer to that, the path to the venv is given by python.defaultInterpreterPath. The python.pythonPath is no longer valid.

So, the settings.json should be like:

{
        "python.defaultInterpreterPath": 
    "C:\\tproj\\tproj_env\\Scripts\\python"
    }
  1. The venv folder should be in a higher level folder than where the settings.json is in. ex: if the project name is tproj and the venv folder (say tproj_env) and codes folder (say tproj_code) are sub-folders. It is recommended to have the settings.json be in the tproj_code sub-folder.
Loku
  • 201
  • 2
  • 5
1

VS Code python extension automatically checks for virtual environments in default virtual environment directories: https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments

If your virtual environment is present in any of these default directories, you just need to activate the environment by selecting it. To select a specific environment, use the 'Python: Select Interpreter' command from the Command Palette (Ctrl+Shift+P). Refer: https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment

Abhishek Poojary
  • 749
  • 9
  • 10
1

Start PowerShell with admin privileges, run the following command:

 Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Remotesigned

Confirm and go! Execution Policy changes have been updated. You can go back to VsCode and activate your virtual env.

1

By setting EVERYTHING up in Visual Studio Code, your virtual environment will not have the configuration that you want.

First use GitBash and type these commands to create your virtual environment. This assumes you are in the correct folder where Python was installed.

python3 -m venv --system-site-packages /c/python/python39/python39_venv
cd /c/python/python39/python39_venv
source /c/python/python39/python39_venv/source/bin/activate
pip install {module of choice}=={version of choice}

If you are in a different folder, then type the full path of python.exe instead of the command python3.

/c/Python/Python39/Scripts/python.exe -m venv --system-site-packages /c/python/python39/python39_venv

Now configure this new virtual environment in Visual Studio Code:

View > Command Palette > type: "Python: Select Interpreter" > type "C:/Python/Python39/python39_venv/Scripts/python.exe"

Depending on the version of Python, the subfolders to python.exe might vary a bit. So manually navigate to the path to confirm the path.

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
1

To Activate your virtual environment, Step 1: Open VSCode Step 2: ener ctrl + shift + p step 3: Enter python: Select Interpreter you should be able to see the virtual environment if in the same folder.

enter image description here

0

Activate your virtual environment:

  1. Open the command prompt (Windows) or terminal (MacOS).
  2. Activate the virtual environment:
  • replace venv with your virtual environment name
  • assumes you use Anaconda or Miniconda as your package manager
conda activate venv

Open the project folder in Visual Studio (VS) Code:

  1. Launch VS Code.
  2. Click on "File" in the menu bar.
  3. Select "Open Folder" or "Open Workspace" (if you have a workspace file).
  4. Navigate to the folder that contains your project files and click "Open."

Configure the Python interpreter in VS Code:

  1. Once your project is open in VS Code, press Ctrl+Shift+P (Windows) or Cmd+Shift+P (MacOS) to open the Command Palette.
  2. Type "Python: Select Interpreter" and select it from the options.
  3. A list of available Python interpreters will appear. Choose the one associated with your virtual environment (it might be labeled with the environment name and path).

If your virtual environment is not listed, select "Enter interpreter path..." and provide the path to the Python executable within your virtual environment.