DEV Community

Setting Up PEP8 and Pylint on VS Code

John Nyingi on January 15, 2019

Formatting Python Code to pass the Maintainability test can be hard; especially if you are not receiving some help. It's in human nature to get t...
Collapse
 
dcsan profile image
dc • Edited

nowadays (june 2020) I get a message of Unknown configuration setting for pep8
has it been renamed flake8 as that does get recognized?

I am trying with various options like this to toggle on/off various linter

{
    "python.linting.pep8Enabled": true,
    "python.linting.pylintEnabled": true,
    "python.linting.flake8Enabled": false,
    "python.linting.enabled": true,
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
        "--line-length",
        "120"
    ],    
    "python.linting.flake8Args": [
        "--max-line-length=120",
        "--ignore=E402",
    ],
    "python.linting.pylintArgs": [
        "--max-line-length=180"
    ],
    "python.formatting.autopep8Args": [
        "--max-line-length=180"
    ], 
    "python.pythonPath": "venv/bin/python"
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
tgmolinari12 profile image
MT

flake8 is a different linter entirely. If you're still looking for PEP 8 formatting, you can install autopep8 and change your "python.formatting.provider" setting to "autopep8".

Collapse
 
ombratteng profile image
Ole-Martin Bratteng

pep8 has been renamed to pycodestyle, so the python.linting.pep8Enabled is not a valid setting anymore. Now it is python.linting.pycodestyleEnabled

Collapse
 
thenextceo profile image
the-next-ceo

well where is the option to open these JSON settings as in ur screenshot

Collapse
 
ianonjuguna profile image
Iano Njuguna

To install the package ensure you are in your project folder and virtualenv is enabled, if not run the following lines in your folder directory
$ virtualenv env

$ source env/bin/activate

In Windows you activate a virtual environment by running the following command:

# Powershell
$ .\env\Scripts\Activate.ps1
Enter fullscreen mode Exit fullscreen mode

or:

# Bash
$ .\env\Scripts\activate
Enter fullscreen mode Exit fullscreen mode
Collapse
 
klvenky profile image
Venkatesh KL

That was simple and straight to the point. Could you write an article to setup vscode for python for an absolute starter. Because, I have setup the venv and I am able to run the python file in pycharm but not in vscode. Any light on that would be great. :)

Collapse
 
j0nimost profile image
John Nyingi

Sure, I'll have it up pretty soon

Collapse
 
sobolevn profile image
Nikita Sobolev

Maybe you can give wemake-python-styleguide a try? It has even more rules than pylint, but does not even try to mess with types.

It has way less false-positives and is based on flake8.

GitHub logo wemake-services / wemake-python-styleguide

The strictest and most opinionated python linter ever!

wemake-python-styleguide

wemake.services Supporters Build Status Coverage Status Github Action Python Version wemake-python-styleguide


Welcome to the strictest and most opinionated python linter ever.

wemake-python-styleguide logo

wemake-python-styleguide is actually a flake8 plugin with some other plugins as dependencies.

Quickstart

pip install wemake-python-styleguide

You will also need to create a setup.cfg file with the configuration.

We highly recommend to also use:

  • flakehell for easy integration into a legacy codebase
  • nitpick for sharing and validating configuration across multiple projects

Running

flake8 your_module.py

This app is still just good old flake8 And it won't change your existing workflow.

invocation resuts

See "Usage" section in the docs for examples and integrations.

We also support Github Actions as first class-citizens Try it out!

What we are about

The ultimate goal of this project is to make all people write exactly the same python code.

flake8 pylint black mypy wemake-python-styleguide
Formats code?
Finds style issues? 🤔 🤔
Finds bugs? 🤔

Cheers!

Collapse
 
mromdhane profile image
Maroua Romdhane

Thank you!

Collapse
 
parsley72 profile image
parsley72

This is no longer working in VSCode 1.37.1 (2019-08-15). If I follow your instructions then run linting I get a message "Linter pep8 is not installed". Installing again doesn't fix it. Clicking "Select Linter" gives you a list of all supported linters but if you select pep8 it then says "Multiple linters are enabled in settings. Replace with 'pep8'?

Collapse
 
moijes12 profile image
Alex

I think the instructions in here might gelp help. In a nutshell:

  • Open the terminal window
  • Activate the relevant python virtual environment
  • Ensure Pylint is installed within this virtual environment pip install pylint
  • Close all instances of VS Code
  • Launch VS Code from within this terminal window (this will ensure the VS Code process will inherit all of the Virtual Env environment settings)

Let me know if it still doesn't work for you.

Collapse
 
petermortensen profile image
Peter Mortensen • Edited

This article has been wholesale plagiarised at Medium by Hemprasad Badgujar (incl. all the different misspellings of Visual Studio Code):

medium.com/seminal/setting-up-pep8...

Collapse
 
j0nimost profile image
John Nyingi

thanks for pointing this out

Collapse
 
khwilo profile image
Khwilo Kabaka

Clear and concise article John.

Collapse
 
acceptableengineering profile image
Mark Mutti

Useful guide, thank you!

Collapse
 
j0nimost profile image
John Nyingi

I appreciate your feedback