I have a python virtual environment declared in my workspace settings, everything is fine with it.
Now I have a build task that calls a make
target which in turn calls a pip package. When I run it, it doesn't use my venv
even though it is the selected interpreter.
I've tried to add a activate venv/...
before calling my make
command but I get a Permission denied
error in the embedded terminal.
How can I use a virtual environment and tasks at the same time?
It might be a little late to answer your question but the trick is to set the command field to point to the virtual environment's python executable instead of the default
python
. If you set up your.vscode
'ssettings.json
correctly you should have something like this in your file:Having this config in your workspace, you can then create a custom task of type
process
using${config:python.pythonPath}
as it's command field.You can read all about it in this section of VSCode's docs.
This example creates a Django
python manage.py migrate
task:I'm late to the party, but this alternative might be useful. If you use pipenv in stead of standard venv, you can use
pipenv run
. It will activate the virtualenv before running the process. For example, this works for building sphinx:I tested with the following tasks.json and it works:
First activate virtual environment and then executes make.