Visual Studio 代码,Python 使用 WSL 进行 linting(Windows Linux 的子系统)

Visual Studio Code, Python linting with WSL (Windows Subsystem for Linux)

我在 64 位 PC 上使用 Windows 10。最近,我开始在 Windows Ubuntu Bash 上使用 VS Code。除了 linting 之外,一切都很好。我试图让它与 pylint 和 pep8 一起工作,但其中 none 有效。我认为问题是由于 linter 的位置引起的。但是,我不知道如何解决这个问题。您可以检查我对 pylint 的设置:

// Whether to lint Python files using pylint.
"python.linting.pylintEnabled": true,

// Severity of Pylint message type 'Convention/C'.
"python.linting.pylintCategorySeverity.convention": "Information",

// Severity of Pylint message type 'Refactor/R'.
"python.linting.pylintCategorySeverity.refactor": "Hint",

// Severity of Pylint message type 'Warning/W'.
"python.linting.pylintCategorySeverity.warning": "Warning",

// Severity of Pylint message type 'Error/E'.
"python.linting.pylintCategorySeverity.error": "Error",

// Severity of Pylint message type 'Fatal/F'.
"python.linting.pylintCategorySeverity.fatal": "Error",

// Path to Pylint, you can use a custom version of pylint by modifying this 
// setting to include the full path.
"python.linting.pylintPath": "pylint",

// Arguments passed in. Each argument is a separate item in the array.
"python.linting.pylintArgs": [],

如有任何帮助,我将不胜感激。谢谢...

据我所知,如果您使用的是 WSL,shell 是一个独立于 VSCode 的环境。这就是 git 扩展程序 won't work unless you install the Windows version, even if you've installed it in WSL. And while it is possible to invoke WSL from Windows 的原因,我无法让它正常工作。

因此,对于 linting,在 Windows 中安装 Python 和 flake8(例如,在 Git Bash 中安装 flake8),你应该没问题。

P.S。如果有人能告诉我其他情况,我很想知道!基本上必须下载两次(一次在 Windows,一次在 WSL),这有点烦人。

切换回 windows 后,我自己一直在为此苦苦挣扎,我发现了这一点: https://github.com/Microsoft/vscode-python/issues/67

哪个是涵盖这个确切场景的未解决问题,评论中有一些 hack 和解决方法,但由于它现在是一个可见的高优先级问题,真正的解决方案是等待 vs code 中的修复.

或者,您可以使用本指南在 WSL 环境中安装 VS Code: https://nickjanetakis.com/blog/using-wsl-and-mobaxterm-to-create-a-linux-dev-environment-on-windows

这将是 运行 VS 代码的 linux 版本,因此它将使用安装在那里的环境进行 linting。

Visual Studio Code 刚刚发布了一个教程,以正确 运行 使用 WSL 的应用程序。

Remote development in WSL