【问题标题】:How to define a virtual environment in vs-code如何在 vs-code 中定义虚拟环境
【发布时间】:2020-10-22 09:54:20
【问题描述】:

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

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

from django.shortcuts import render

棉绒说

无法导入 'django.shortcuts'pylint(import-error)

我的 virtualenvs 在目录 ~/Envs

ls -l Envs

返回

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 Path 和/或 Python: Venv Folders 设置为 ~/Envs~/环境/django。我已经重启了vs-code,但是问题依旧

我该怎么办?

【问题讨论】:

标签: python django vscode-settings


【解决方案1】:

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

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

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2022-11-21
      • 2018-08-20
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 2023-03-26
      相关资源
      最近更新 更多