Setup Flake8 in Pycharm
Quick setup & configuration guide
To run Flake8 automatically in PyCharm, you can set it up as an external tool that will be triggered upon saving a file. Here’s how you can configure it:
Install Flake8:
Open an interactive shell and run the following command to install Flake8:
python -m pip install flake8Ensure that you install Flake8 on the correct version of Python that you’re using in PyCharm1.
Configure PyCharm:
In PyCharm, go to
File -> Settings -> Tools -> External Tools.Click on
Addto create a new tool configuration.Set the Name to
Flake8.In the Program field, enter the path to your Python interpreter followed by
/python. It should look something like this:$PyInterpreterDirectory$/pythonIn the Arguments field, enter
-m flake8.In the Working directory field, enter the path to the project or file you want to lint.
Set Up File Watchers:
Go to File -> Settings -> Tools -> File Watchers.
Click the “+” and select <custom>.
Set the File type to “Python”.
Set the Scope to “Current File”.
For the Program, enter the path to the
flake8executable or your Python interpreter followed by-m flake8.In the Arguments field, use
$FilePathRelativeToProjectRoot$.Set the Output paths to
$ProjectFileDir$/flake8_report.txtto save the report.
Run Flake8:
After configuring, you can run Flake8 by selecting the tool from the
Tools -> External Toolsmenu in PyCharm.
Enable Automatic Triggering:
In the Advanced Options of the File Watcher, ensure “Auto-save edited files to trigger the watcher” is checked.
Now, every time you save a Python file, Flake8 will run automatically and check for any style or logical errors in your code.
NOTE: Remember, if you want to use Flake8 with PyCharm’s Pylint plugin, you can install the flake8-for-pycharm package, which will allow Flake8 to emulate Pylint’s output.

