pylint在所有导入的库中标记错误

问题描述 投票:0回答:1

我正在将pylintVisual Studio Code一起使用,并且工作正常,除了它在不是[或我的模块的所有import子句中标记了错误项目。从Django,Django Rest Framework等导入时标记为错误。

enter image description hereenter image description here

我如何配置pylint以识别已安装并正在运行的这些库(我没有从python得到任何错误?

python visual-studio-code pylint
1个回答
1
投票
您需要设置正确的Python解释器。参见VS Code文档> Select and activate an environment

基本上:

    打开命令面板(
  1. Ctrl + Shift + P + Shift + P
  2. 输入“
  3. Python:选择解释器”]
  4. 选择安装了[[both Django和pylint的Python环境]
  5. 重新打开文件
您可以确认从状态栏中选择的当前环境。
  • enter image description here

    您还可以从工作区的

    settings.json

  • 中进行检查,每次切换环境时,python.pythonPath设置都会自动添加/更新:

    { "python.pythonPath": "/Users/gino/.venvs/test-django/bin/python", ... } Pylint基本上检查当前激活的环境中是否存在导入错误。

    如果错误没有立即消失,请尝试重新加载VS Code。 
    © www.soinside.com 2019 - 2024. All rights reserved.