Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using Windows 10 on 64 bit PC. Recently, I started using VS Code with Ubuntu Bash on Windows. Everything works great except linting. I tried to get it working with pylint and pep8 but none of them worked. I think that the problem is caused because of the location of the linter. However, I couldn't figure out how to fix the problem. You can check my settings for the 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": [],

I would appreciate any help. Thank you...

like image 255
batatop Avatar asked Oct 05 '17 19:10

batatop


People also ask

How do I fix Visual Studio Code lint issues?

Go to File > Preferences > Settings (or Code > Preferences > Settings). Then click settings. json . Now, undo the fixes you made to the JavaScript file you created earlier.

Does Visual Studio work with WSL?

Visual Studio's WSL 2 toolset allows you to use Visual Studio to build and debug C++ code on WSL 2 distros without adding a SSH connection. You can already build and debug C++ code on WSL 1 distros using the native WSL 1 toolset introduced in Visual Studio 2019 version 16.1.


2 Answers

From what I can tell, if you're using WSL, the shell is a separate environment from VSCode. That's why the git extension 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, I've not been able to get it working.

So for linting, install Python and flake8 in Windows (e.g. pip install flake8 in Git Bash) and you should be fine.

P.S. If someone can tell me otherwise, I'd love to know! It's a bit annoying having to essentially download stuff twice (once in Windows, once in WSL).

like image 166
wasabigeek Avatar answered Sep 19 '22 08:09

wasabigeek


I've been struggling with this myself after switching back to windows , I found this: https://github.com/Microsoft/vscode-python/issues/67

Which is the open issue that covers this exact scenario, there are a couple hacks and work arounds in the comments but as it is now a visible and high priority issue the real solution is to wait for a fix in vs code.

Alternatively you can install VS Code in the WSL environment using this guide: https://nickjanetakis.com/blog/using-wsl-and-mobaxterm-to-create-a-linux-dev-environment-on-windows

This would be running the linux version of VS code so it would be linting using the environments installed there.

like image 30
Sam Bradley Avatar answered Sep 17 '22 08:09

Sam Bradley