Skip to content

Make Tasks aware of virtual environments #1664

Closed

Description

This is an enhancement request.

Environment data

  • VS Code version: 1.23.1
  • Extension version (available under the Extensions sidebar): 2018.4.0
  • OS and version: Windows 10 Pro
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pipenv
  • Relevant/affected Python packages and their versions: N/A

Actual behavior

When running a Task that calls the python executable, the system-level interpreter is used instead of the copy inside the virtual environment. This obviously fails if the command depends on packages that are only installed inside the virtual environment.

E.g., running the following task, which depends on the grpcio-tools package (where the grpc_tools module lives)

{
      "label": "Run GRPC compiler",
      "type": "shell",
      "command": "python -m grpc_tools.protoc -I. --python_out=grpc_artifacts --grpc_python_out=grpc_artifacts myservicedefinition.proto"
    }

produces this output

C:\Python36\python.exe: Error while finding module specification for 'grpc_tools.protoc' (ModuleNotFoundError: No module named 'grpc_tools')
The terminal process terminated with exit code: 1

If I prepend pipenv run to the command everything works as expected, but I thought the Task would be smart enough to do that (or something equivalent) on its own.

Expected behavior

Tasks that call the Python interpreter should do it inside the virtual environment.

Steps to reproduce:

  1. Create a python project with a virtual environment.
  2. Open the project in VS Code.
  3. Install a package (VS code will correctly install it inside the virtual environment).
  4. Create a task that calls python and somehow uses the package installed in step 3 (for an example see section Actual behavior above )
  5. Execute the task.

Activity

  1. brettcannon commented on May 14, 2018

    @brettcannon
    Member

    https://code.visualstudio.com/docs/editor/tasks#_variable-substitution has docs on how to do this, but basically you want ${config:python.pythonPath} to get the interpreter that you set.

  2. locked as resolved and limited conversation to collaborators on Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions