如何在 vs-code 中定义虚拟环境

How to define a virtual environment in vs-code

我是 vs-code 的新手(昨天开始使用它,我喜欢它)

我有轻微的不适。我正在做一个 django 项目,我正在使用带有 virtualenvwrapper 的 virtualenv。我遇到的问题是(例如)在

from django.shortcuts import render

linter 说

Unable to import 'django.shortcuts'pylint(import-error)

我的 virtualenvs 在目录 ~/Envs and

ls -l Envs

returns

drwxr-xr-x 4 jeff jeff 4096 Jun 18 14:46 django
-rwxr-xr-x 1 jeff jeff  135 Jun 18 15:23 get_env_details
-rw-r--r-- 1 jeff jeff   96 Jun 18 15:23 initialize
-rw-r--r-- 1 jeff jeff   73 Jun 18 15:23 postactivate
-rw-r--r-- 1 jeff jeff   75 Jun 18 15:23 postdeactivate
-rwxr-xr-x 1 jeff jeff   66 Jun 18 15:23 postmkproject
-rw-r--r-- 1 jeff jeff   73 Jun 18 15:23 postmkvirtualenv
-rwxr-xr-x 1 jeff jeff  110 Jun 18 15:23 postrmvirtualenv
-rwxr-xr-x 1 jeff jeff   99 Jun 18 15:23 preactivate
-rw-r--r-- 1 jeff jeff   76 Jun 18 15:23 predeactivate
-rwxr-xr-x 1 jeff jeff   91 Jun 18 15:23 premkproject
-rwxr-xr-x 1 jeff jeff  130 Jun 18 15:23 premkvirtualenv
-rwxr-xr-x 1 jeff jeff  111 Jun 18 15:23 prermvirtualenv
drwxr-xr-x 4 jeff jeff 4096 Jun 18 15:26 wagtail

我在 venv 工作 django

我试过设置 Python: Venv 路径 and/or Python: Venv 文件夹~/Envs~/Envs/django。我重启了vs-code,问题依旧

我该怎么办?

你试过这样吗: 要 select 特定环境,请使用命令面板 (Ctrl+Shift+P) 中的 Python: Select 解释器命令。

您可以随时切换环境;切换环境可帮助您根据需要使用不同的解释器或库版本测试项目的不同部分。

Python: Select 解释器命令显示可用全局环境、conda 环境和虚拟环境的列表。 (有关详细信息,包括这些环境类型之间的区别,请参阅扩展在何处查找环境部分。)例如,下图显示了几个 Anaconda 和 CPython 安装以及一个 conda 环境和一个虚拟环境(env) 位于工作区文件夹中:

来源: https://code.visualstudio.com/docs/python/environments

尝试将 Python 解释器设置为带有 venv 的选项。