VS Code 任务和 Python 虚拟环境 [英] VS Code task and Python virtual environment

查看:49
本文介绍了VS Code 任务和 Python 虚拟环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的工作区设置中声明了一个 python 虚拟环境,一切都很好.

I have a python virtual environment declared in my workspace settings, everything is fine with it.

现在我有一个调用 make 目标的构建任务,该目标又调用一个 pip 包.当我运行它时,它不使用我的 venv 即使它是选定的解释器.

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.

我尝试在调用我的 make 命令之前添加一个 activate venv/... 但我收到一个 Permission denied 错误嵌入式终端.

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?

推荐答案

我使用以下 tasks.json 进行了测试,并且可以正常工作:

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"
    }
  ]
}

先激活虚拟环境,然后执行make.

First activate virtual environment and then executes make.

这篇关于VS Code 任务和 Python 虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆