Visual Studio Code 中的 Pylint“未解析導入”錯誤 - Pylint "unresolved import" error in Visual Studio Code

問題:

I am using the following setup我正在使用以下設置

  • macOS v10.14 (Mojave) macOS v10.14 (莫哈韋沙漠)
  • Python 3.7.1蟒蛇 3.7.1
  • Visual Studio Code 1.30 Visual Studio 代碼 1.30
  • Pylint 2.2.2派林特 2.2.2
  • Django 2.1.4 Django 2.1.4

I want to use linting to make my life a bit easier in Visual Studio Code.我想使用 linting 讓我在 Visual Studio Code 中的生活更輕鬆。 However, for every import I have states "unresolved import".但是,對於每次導入,我都聲明“未解決的導入”。 Even on default Django imports (ie from django.db import models).即使是默認的 Django 導入(即從 django.db 導入模型)。

I presume it is because it is not seeing the virtual environment Python files.我認爲這是因爲它沒有看到虛擬環境 Python 文件。

Everything works just fine, but it's starting to get annoying.一切正常,但它開始變得煩人。

The interpreter choices I have are all system versions of Python.我選擇的解釋器都是 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).它似乎根本沒有看到我的虛擬環境 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.如果我在settings.json文件中設置了python.PythonPath ,它只會忽略它並且不會列出我的虛擬環境路徑作爲選項。 I also tried setting it up in my global Python settings, but it also does not show up.我也嘗試在我的全局 Python 設置中設置它,但它也沒有顯示出來。

Is there a quick fix to get it working?有沒有快速解決辦法讓它工作?


解決方案:

參考一: https://en.stackoom.com/question/3eKBz
參考二: https://stackoom.com/question/3eKBz
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章