Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Tasks aware of virtual environments #1664

Closed
alexvy86 opened this issue May 11, 2018 · 1 comment
Closed

Make Tasks aware of virtual environments #1664

alexvy86 opened this issue May 11, 2018 · 1 comment

Comments

@alexvy86
Copy link

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.
@brettcannon
Copy link
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.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants