Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have multiple subfolders with virtual python environments in VS Code?

I have a monorepo structured like this:

myRepo/
├─ project_1/
│  ├─ .venv/
│  ├─ main.py
├─ project_2/
│  ├─ .venv/
│  ├─ main.py
├─ .gitignore
├─ README.md
  • Can VS Code handle multiple python venvs in subfolders?

After some googling I managed a find one solution, but its not very elegant. I created a workspace and added the folders /project_1 and /project_2, that worked and I can easily switch and select Python Interpreter. I also need to modify files in /root from time to time so I added this folder as well. All this makes the Explorer folder structure bigger and more cluttered with duplicates of itself:

workspace/
├── myRepo/
│   ├── project_1/
│   │   ├── .venv/
│   │   └── main.py
│   ├── project_2/
│   │   ├── .venv/
│   │   └── main.py
│   ├── .gitignore
│   ├── README.md
│   └── myRepo/
├── project_1/
│   ├── .venv/
│   └── main.py
└── project_2/
    ├── .venv/
    └── main.py
like image 730
NorwegianClassic Avatar asked Dec 08 '25 10:12

NorwegianClassic


2 Answers

Hard to figure out, took me a few hours so I'll leave this here for reference.

How to create separate virtual environments: microsoft/vscode-python "Mono Repo Set-up Guide"

TL;DR

  1. Open root folder (myRepo)
  2. Click on File > Add Folder to Workspace...
  3. Select all project folders you want to add as a workspace (project_1, project_2)
  4. For each project/workspace, create a virtual environment.
like image 92
Christopher Kiessling Avatar answered Dec 10 '25 23:12

Christopher Kiessling


VS Code has a list of places, where it looks for virtual environments. Only environments located directly under the workspace are picked up automatically. You can also enter custom paths when running the Python: Select Interpreter command, though. Simply select "Enter interpreter path..." and navigate to your venv's /bin/python executable:

select interpreter

enter interpreter path

find

python binary

Once you have used a cutom interpreter path, it is known to VS code and will be directly selectable using the Python: Select Interpreter command.

like image 40
carlfriedrich Avatar answered Dec 10 '25 23:12

carlfriedrich



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!