【问题标题】:Visual Studio Code, Python linting with WSL (Windows Subsystem for Linux)Visual Studio Code, Python linting with WSL (Windows Subsystem for Linux)
【发布时间】:2018-03-17 13:02:27
【问题描述】:

我在 64 位 PC 上使用 Windows 10。最近,我开始在 Windows 上使用 VS Code 和 Ubuntu Bash。除了掉毛,一切都很好。我试图让它与 pylint 和 pep8 一起工作,但它们都不起作用。我认为问题是由于 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": [],

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

【问题讨论】:

  • “Bash on Windows”又名 WSL 是一个命令行环境。在其中使用 GUI 编辑器(VS Code)有什么意义?无论如何,主机 Windows 和“bash”容器共享的文件夹的路径以 /mnt/c (或其他驱动器号)开头,是的,您需要在 Windows 和 bash 端使用不同的路径。 RTFM。
  • @ddbug 感谢您的评论。 VS Code 是适用于任何编程语言的代码编辑器。我正在使用 bash 通过编辑器编译代码。但是,linter 已经安装在 bash 中。因此,我不需要 /mnt/c 在 Windows 中访问我的文档。我试过 "C:\\Users\\user\\AppData\\Local\\lxss\rootfs\\usr\bin\\pylint" 但也没有用。

标签: python visual-studio-code vscode-settings windows-subsystem-for-linux bash-on-windows


【解决方案1】:

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

Remote development in WSL

【讨论】:

  • 另外我目前没有用 Python 编写,所以我没有测试它是否能解决问题。刚发布就想分享一下。
【解决方案2】:

切换回 windows 后,我自己一直在努力解决这个问题,我发现了这个: https://github.com/Microsoft/vscode-python/issues/67

这是涵盖此确切场景的未解决问题,在 cmets 中有一些技巧和解决方法,但由于它现在是一个可见且高优先级的问题,真正的解决方案是等待 vs 代码中的修复。

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

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

【讨论】:

    【解决方案3】:

    据我所知,如果您使用的是 WSL,那么 shell 是与 VSCode 分开的环境。这就是为什么 git 扩展 won't work 除非你安装了 Windows 版本,即使你已经在 WSL 中安装了它。虽然可以invoke WSL from Windows,但我无法让它工作。

    所以对于 linting,在 Windows 中安装 Python 和 flake8(例如,在 Git Bash 中安装 pip install flake8)就可以了。

    附:如果有人可以告诉我,我很想知道!基本上必须下载两次(一次在 Windows,一次在 WSL),这有点烦人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-11
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      相关资源
      最近更新 更多