简体   繁体   English

pylint 标记所有已安装库的导入错误

[英]pylint marks error with all imports for libraries installed

I am using pylint with Visual Studio Code , and it works fine, with the exception that it marks error in all import clauses that are not modules from python or from my project.我正在将pylintVisual Studio Code 一起使用,它工作正常,但它在所有不是来自python或我的项目的模块的import子句中标记错误。 It marks error with imports from Django, Django Rest Framework, etc.它标记了从 Django、Django Rest Framework 等导入的错误。

在此处输入图片说明 在此处输入图片说明

How can I configure pylint to recognize these libraries that are installed and working (I don't get any error from python)?如何配置 pylint 以识别这些已安装和正在运行的库(我没有从 python 中收到任何错误)?

You need to set the correct Python interpreter.您需要设置正确的 Python 解释器。
See the VS Code docs > Select and activate an environment .请参阅 VS Code 文档 > 选择并激活环境

Basically:基本上:

  1. Open the Command Palette ( Ctrl + Shift + P or + Shift + P )打开命令面板( Ctrl + Shift + P + Shift + P
  2. Enter " Python: Select Interpreter "输入“ Python:选择解释器
  3. Select the Python environment where both Django and pylint is installed选择安装Django和pylint的两个Python环境
  4. Reopen the file重新打开文件

You can confirm the current environment selected from the status bar.您可以确认从状态栏中选择的当前环境。

在此处输入图片说明

You can also check it from the workspace's settings.json , where a python.pythonPath settings gets automatically added/updated every time you switch environments:您还可以从工作区的settings.json 中检查它,每次切换环境时都会自动添加/更新python.pythonPath设置:

{
    "python.pythonPath": "/Users/gino/.venvs/test-django/bin/python",
    ...
}

Pylint basically checks the currently activated environment for import errors. Pylint 基本上会检查当前激活的环境是否存在导入错误。

If the errors does not instantly disappear, try reloading VS Code.如果错误没有立即消失,请尝试重新加载 VS Code。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM