【问题标题】:How do I configure Visual Studio Code with Python extension to not complain about inability to import modules?如何使用 Python 扩展配置 Visual Studio Code,以免抱怨无法导入模块?
【发布时间】:2017-01-18 21:25:53
【问题描述】:

我是 VS Code 的新手,我安装了例如PySide 用于我用 Python 编写的教程项目。我尝试:

from PySide.QtGui import QDialog, QApplication, QVBoxLayout, QLineEdit, QTextBrowser
from PySide.QtCore import *

虽然代码使用导入的模块运行良好,但 VS Code 抱怨:

[pylint] E0401:Unable to import 'PySide.QtGui'

或

[pylint] E0401:Unable to import 'PySide.QtCore'

这很烦人,因为我可以按预期使用这些模块。我猜是配置问题,但不知道如何解决。

非常感谢。

另见:

Visual representation of VS Code complaining

编辑:

我使用 PySide 的预编译版本。这可能是这种行为的原因吗?

【问题讨论】:

标签: python qt pyside visual-studio-code


【解决方案1】:

@安德烈亚斯·施瓦布, 你需要确保 pylint 安装在你安装了 PySide 包的 python 环境中。 您还需要确保在 python.pythonPath 设置的 settings.json 中引用了相同的环境(python 解释器)。

您可以在此处找到有关这两者的更多详细信息:

【讨论】:

  • 不幸的是,这里提供的解决方案:github.com/DonJayamanne/pythonVSCode/wiki/… 不起作用。我还没有设置虚拟环境。
  • Andreas Schwab,请您在 GitHub 上为此提出问题。在那里解决它会更容易,因为我们可以共享更多信息,例如屏幕转储等。例如。分享你的 launch.json 和 settings.json 等
【解决方案2】:

随着 Visual Studio Code 1.6 的更新和相应的 Python 扩展,问题不再出现。

【讨论】:

    【解决方案3】:

    确保你已经在你的环境中安装了 pylint(虚拟环境以防万一)

    pip install pylint
    

    【讨论】:

      猜你喜欢
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 2017-02-13
      • 1970-01-01
      相关资源
      最近更新 更多