pythonvisual-studio-code

VS Code task and Python virtual environment


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?


Solution

  • I tested with the following tasks.json and it works:

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "test",
          "type": "shell",
          "command": "source /home/me/.pyenvs/myenv/bin/activate; make"
        }
      ]
    }
    

    First activate virtual environment and then executes make.