Skip to content

Instantly share code, notes, and snippets.

@tossmilestone
Created March 30, 2018 06:55
Show Gist options
  • Select an option

  • Save tossmilestone/23139d870841a3d5cba2aea28da1a895 to your computer and use it in GitHub Desktop.

Select an option

Save tossmilestone/23139d870841a3d5cba2aea28da1a895 to your computer and use it in GitHub Desktop.
Flake8 integrated with PyCharm
How to manually setup flake8 as PyCharm external tool
File / Settings / Tools / External Tools / Add
Name: Flake8
Program: $PyInterpreterDirectory$/python
Parameters: -m flake8 --max-complexity 10 --ignore E501 $FilePath$
Working directory: $ProjectFileDir$
Output Filters / Add
Name: Filter 1
Regular expression to match output:
$FILE_PATH$\:$LINE$\:$COLUMN$\:.*
Output Filters / Add
Name: Filter 2
Regular expression to match output:
$FILE_PATH$\:$LINE$\:.*
To check source with flake8:
Tools / External Tools / Flake8
Can be used with single files as well as with directories, recursively.
@myheartsgoon
Copy link

thanks, it helps

@wufu-fire
Copy link

not work, errors: permission denied.

@Den4i
Copy link

Den4i commented Oct 15, 2019

thx, it working

@jantonacci
Copy link

@gilsondev
Copy link

Using this config with file watcher:

https://tirinox.ru/flake8-pycharm/

@kwanUm
Copy link

kwanUm commented Feb 24, 2021

Can flake8 be configured to run automatically in pycharm?

@patrickwerz
Copy link

How can I use a flake8 config file (setup.cfg) together with the external tooling?

@tossmilestone
Copy link
Author

tossmilestone commented Apr 15, 2021

How can I use a flake8 config file (setup.cfg) together with the external tooling?

@patrickwerz
I think you can add the setup.cfg to the Parameters:

Parameters: -m flake8 --max-complexity 10 --ignore E501 $FilePath$

and use the $ProjectFileDir$ to locate your setup.cfg.

@ulan-yisaev
Copy link

Thank's a lot, really helpful info! 👍

@MeboxForever
Copy link

thanks for helps!!

@haim0n
Copy link

haim0n commented Nov 11, 2021

Created a small repo for pycharm external tools (currently flake8 and black supported ) for applying to a code selection from pycharm.
Maybe this will be somewhat helpful to anyone: https://github.com/haim0n/pycharm_ext_tools

@banagale
Copy link

Thank you, @haim0n!

@lucasslima
Copy link

Thank you, worked like a charm!

@haim0n
Copy link

haim0n commented Jul 31, 2023

Cheers , glad to help :)

Just bear in mind that flake8 deprecated the support for --diff option in its next versions: https://flake8.pycqa.org/en/latest/release-notes/5.0.0.html#deprecations

@JonZavialov
Copy link

This was useful but it should be noted that it only logs the Flake8 output in the terminal. This library worked well for me to integrate the output into Pycharm's Pylint plugin.

@Day0Dreamer
Copy link

Day0Dreamer commented Jan 18, 2026

Hey there, I managed to configure WSP using LSP4IJ in PyCharm and good old pipx. I assume you have pipx.

pycharm64_tG0HlsuShp

Here's how

1 Install python-lsp-server

# Install pylsp
pipx install "python-lsp-server[flake8]"

# Inject required plugins
pipx inject python-lsp-server wemake-python-styleguide
pipx inject python-lsp-server pyls-flake8

Important: The [flake8] extra does NOT install the flake8 plugin — you must manually inject pyls-flake8.

2 Verify Installation.

pipx runpip python-lsp-server list
# or 
pipx runpip python-lsp-server list | grep -E "(flake8|wemake|pyls-flake8|Flake8-pyproject)"

Expected output:

flake8                    7.x.x
pyls-flake8               0.x.x
wemake-python-styleguide  1.x.x

3 Find pylsp Executable Path

where pylsp

Note the path: C:\Users\Day\.local\bin\pylsp.exe

4 Create LSP server

  1. Settings → Languages & Frameworks → Language Server Protocol → Server Definitions
  2. Click "+" to add a new server
  3. Configure:
Field Value
Name pylsp-flake8
Path C:\Users\Day\.local\bin\pylsp.exe
  1. In the Configuration tab, add this JSON:
{
  "pylsp": {
    "plugins": {
      "flake8": {
        "enabled": true,
        "maxLineLength": 70,
        "select": ["WPS", "E"],
        "ignore": ["WPS111", "WPS602"]
      },
      "pycodestyle": {
        "enabled": false
      },
      "pyflakes": {
        "enabled": false
      }
    }
  }
}

or

{
  "pylsp": {
    "plugins": {
      "flake8": {
        "enabled": true,
        "config": "C:\\...whatever...\\.flake8"
      },
      "pycodestyle": { "enabled": false },
      "pyflakes": { "enabled": false },
      "mccabe": { "enabled": false },
      "pyls_isort": { "enabled": false },
      "pylsp_mypy": { "enabled": false },
      "rope_autoimport": { "enabled": false },
      "rope_completion": { "enabled": false }
    }
  }
}
  1. In Mappings - Language - Languages add the Python language.

  2. Click OK

5 Restart PyCharm

Restart PyCharm completely for the LSP server to initialize.

6 Test Inline Errors

Create a test file with intentional WPS errors:

# test_wps_errors.py
"""Test file with WPS errors."""

# WPS407: Mutable module constant
ITEMS_LIST = []

# WPS110: Wrong variable name
data = {"key": "value"}
obj = object()

def process(x):
    # WPS421: Wrong function call (print)
    print("Processing...")
    # WPS432: Magic number
    return x * 3.14159
  • WPS errors appear as inline squiggles (yellow/orange underlines)
  • Hovering shows the WPS error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment