5

I'm playing with Visual Studio Code on Ubuntu. One big problem is I can't figure out how to attach a virtualenv to a file. So, I open the file. On the lower left corner, I see the default path to the system python executable:

enter image description here
(Click image to enlarge)

when I click on it, a list with two paths is shown on the top middle box (both are the default system python's).

I tried to set the python.venvPath (in green in the right window). but it does not work.

My question is: how to assign a virtualenv to a project, so that whenever I open that file, it uses that venv?

1 Answer 1

4

I simply set the pythonPath variable in the local .vscode/settings.json to the python that should be used, like so:

"python.pythonPath": "~/.virtualenvs/<my_virtual_env>/bin/python"

Code then automatically sources the virtualenv activate script before running files (like debugging or "run python file in terminal").

I use Ubuntu 18.04, Code 1.33.0 and Python Plugin 2019.3 from Microsoft

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .