如何在 vs 代码中为 python2 和 python3 配置 pylint

How to configure pylint for both python2 and python3 in vs code

我在两个 windows 中有两个项目,一个在 python2 中,另一个在 python3.

Is there anyway I can use both pylint for python2 and python3 in vscode for different projects on the fly ?

我试过了,但我不能同时使用它们。我可以设置 python2 pylint 或 python3 一个。

是的,有办法。

您可以为您在vscode中打开的每个文件夹(项目)设置一个解释器。这将决定 linting(假设您为每个解释器安装了模块)。通过这种方式,您可以同时打开两个不同的项目,每个项目都将使用其设置的解释器和 linter。

  • 自动方式
    select 当前项目文件夹的解释器的理想方法是打开命令选项板 (F1) 并键入 "Python: Select Workspace Interpreter" 并从下拉列表中选择(在您打开项目的同时)。就是这样。 Vscode 将使用该解释器和 linter。

  • 手动方式
    现在,如果当你尝试 select 像我上面描述的解释器时,你会收到这样的消息: "There are no entries to select from" 即使你安装了两个解释器,就像我遇到的那样(当我尝试 Windows,我想可能是因为 Windows 的 Python 启动器)。您仍然可以 select 解释器。您只需要手动完成即可。
    当您打开项目时,在 de 命令面板上写入 "Preferences: Open Workspace Settings" 并按回车键。这将在项目文件夹内的隐藏 .vscode 文件夹中创建并打开一个空 settings.json 文件。在此文件中,您可以设置要在项目中使用的确切 python 解释器。例如,对于 python 2,像这样:
    "python.pythonPath": "C:\Python27\python.exe"
    有了它,您应该能够使用特定的解释器进行 lint 和调试。