0

I have multiple VS Code workspaces for different projects. Each of these workspaces has a dedicated virtual environment.

I want to write a Python script to create new venvs in bulk, then assign each venv to its workspace/project by modifying the settings.json file.

The reason for doing this is because I like to refresh the venvs regularly, and have different versions of Python for different projects. I can also automate running pip install -r requirements.txt for each project. Doing this manually is quite an overhead and a script to automate this is easy.

But, I'm struggling with VS Code. So far this is what I have in the workspace settings.json file:

{
 "python.defaultInterpreterPath": "/home/user/venv/devvenv/venvname/bin/python3.13",
 "python.terminal.activateEnvironment": true
}

When I open VS Code and run an .ipynb notebook, I am asked for an interpreter. It does give me the option of the specified venv.

When I open a Terminal, no venv is activated.

When I run a .py file, VS Code uses the OS (Ubuntu) default interpreter.

How can I automate VS Code settings so that:

  • .ipynb notebooks automatically use the correct venv
  • Terminal automatically activates the correct venv on open
  • .py files are executed with the correct venv

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.