Pylint“未解决的进口” Visual Studio代码中的错误 [英] Pylint "unresolved import" error in Visual Studio Code

查看:205
本文介绍了Pylint“未解决的进口” Visual Studio代码中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下设置


  • macOS v10.14 (Mojave)

  • Python 3.7.1

  • Visual Studio Code 1.30

  • Pylint 2.2.2

  • Django 2.1.4

  • macOS v10.14 (Mojave)
  • Python 3.7.1
  • Visual Studio Code 1.30
  • Pylint 2.2.2
  • Django 2.1.4

我想使用棉绒来制作我的在Visual Studio Code中使生活变得更轻松。但是,对于每个导入,我都有未解决的导入状态。即使在默认的Django导入中(即从django.db导入模型)。

I want to use linting to make my life a bit easier in Visual Studio Code. However, for every import I have states "unresolved import". Even on default Django imports (i.e. from django.db import models).

我认为这是因为它没有看到虚拟环境Python文件。

I presume it is because it is not seeing the virtual environment Python files.

一切正常,但开始变得烦人。

Everything works just fine, but it's starting to get annoying.

我拥有的解释器选择都是Python的系统版本。似乎根本看不到我的虚拟环境Python(它与我的工作空间不在同一个目录中,因此该部分有意义)。

The interpreter choices I have are all system versions of Python. It does not seem to see my virtual environment Python at all (it is not in the same directory as my workspace, so that part makes sense).

如果我设置了 settings.json 文件中的python.PythonPath ,它只会忽略它,不会将我的虚拟环境路径作为选项列出。我也尝试在全局Python设置中对其进行设置,但它也没有显示。

If I set up the python.PythonPath in the settings.json file, it just ignores it and does not list my virtual environment path as an option. I also tried setting it up in my global Python settings, but it also does not show up.

是否有快速解决方案使其正常工作?

Is there a quick fix to get it working?

推荐答案

导入自己的模块时,可接受的答案无法解决错误。

The accepted answer won't fix the error when importing own modules.

在工作区设置中使用以下设置 .vscode / settings.json

Use the following setting in your workspace settings .vscode/settings.json:

"python.autoComplete.extraPaths": ["./path-to-your-code"],

参考: 问题排查,无法解决的导入警告

这篇关于Pylint“未解决的进口” Visual Studio代码中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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