How to run Pylint with PyCharm
Solution 1
You can set up Pylint to work with PyCharm by following the following steps:
-
Install
pylint
:$ pip install pylint
-
Locate your
pylint
installation folder:$ which pylint # MacOS/Linux /usr/local/bin/pylint # This is just a possible output - check yours <!--> $ where pylint # Windows %LocalAppData%\Programs\Python\Python36-32\Scripts\pylint.exe # Possible location
-
Open the PyCharm settings window with menu File → Settings, then navigate to menu Tools → External Tools in the sidebar. (Or search "external tools")
-
Set up an external tool by clicking on the
+
sign and filling in the fields accordingly. In Program use the path you got when runningwhich pylint
. For the other values, you can use the same from the image. -
Run
pylint
from menu Tools → External Tools → pylint: -
Look at your output in the PyCharm terminal
For more details, refer to Pylinting with PyCharm.
If you want to use Pylint to check your whole project or a particular file or directory, you can right click on your project root, file or directory, then activate External Tools → pylint as shown below.
Solution 2
Because I didn't find a working ready-made setup, these are the settings I use in PyCharm CE 2018.1 on macOS:
1 - pip install pylint
in your project virtualenv or globally
2 - Add new external tool and configure:
Program: pylint
Arguments: "--msg-template='{abspath}:{line:5d},{column:2d}: {msg} ({symbol})'" --output-format=colorized "$FilePath$"
Working directory: $ProjectFileDir$
Output filters: $FILE_PATH$:\s*$LINE$\,\s*$COLUMN$:
Notice the required double quotes for the msg-template, and the escape chars for the output filters. The output filter allows to click on the file path and open the location in the IDE source editor.
Only missing feature would be the output filters to plot the lint descriptions directly into the source view, as is done with the builtin linter. No such feature at this time though.
Solution 3
You can try this Pylint PyCharm plugin:
It provides both real-time and on-demand scanning of Python files with Pylint from within PyCharm/IntelliJ IDEA.
Once you have it installed, the real-time inspection works automatically. For the on-demand you have several options that go from just checking the current open file to scan the entire project:
(Just for the sake of transparency, I am the developer.)
Solution 4
I now use and recommend the PyCharm plugin which didn't exist when I first wrote this answer.**
A colleague pointed me towards pylint-pycharm on GitHub. It's a wrapper around Pylint with output formatted for PyCharm.
Here's how I set it up:
git clone https://github.com/perses76/pylint-pycharm.git
cd pylint-pycharm
python setup.py build
This creates build/scripts-2.7/pylint-pycharm
Then, in PyCharm, create a new External Tool with these settings:
Program: path to your installation of pylint-pycharm
Arguments: --virtualenv=$PyInterpreterDirectory$/.. $FileName$
Working directory: $FileDir$
Output filters: $FILE_PATH$\:$LINE$\:$COLUMN$\:.*
Now run it from menu Tools* → External Tools → PyLintPyCharm. Each line of output will be hyperlinked to the relevant position in the source code.
Solution 5
A note on the previous answers. I was searching for a method to make PyCharm aware of the output syntax so I can directly jump to the file locations. That works without using additional tools.
Pylint can be configured to output messages in a specific format using the msg-template
option in the pylintrc file or the CLI option --msg-template
.
I set it to:
msg-template='{abspath}:{line}:{column}: {msg_id} {msg}'
In the External Tools settings, the Output filters:
can be set to
$FILE_PATH$:$LINE$:$COLUMN$: .*
so PyCharm shows links to directly jump to the reported locations.
This can be combined with output-format=colorized
so I get this:
PyCharm does not recognize the column despite having it configured. But having the file and line is enough for me.
Wasif Hyder
Updated on July 08, 2022Comments
-
Wasif Hyder almost 2 years
I want to configure Pylint as an external tool in my entire project directory for a Python project that I'm working on. I've tried to use the repository as a module with
__init__.py
and without, and it's not working either way.I'm having difficulty setting up Pylint to run with PyCharm. I know that I should be running it as an external tool, however the settings confuse me.
The authoritative source on their documentation is broken, so I can't check that up either.
-
Rod Chen almost 8 yearsI followed the example, but got an error while running. Cannot run program "pylint" (in directory "/Users/RodChen/my_project"): error=2, No such file or directory. I am sure the directory exists cause I use $FileDir$ as working directory. How can I fix it? Thx.
-
ikreb almost 8 yearsI guess that you use windows. Does pylint work at the terminal?
-
Rod Chen almost 8 yearsI use Mac. I only installed pylint in the virtual environment which I am working, and pylint is not working at the normal terminal. After I installed pylint in the system, pylint worked in PyCharm! Thank you!
-
Marc over 6 years@RodChen I also have
pylint
install in a virtual environment. I've pointed PyCharm to my virtual environment's python interpreter and it seems to work fine. I'm very new topylint
though, so maybe you're referring to some particular functionality I'm not aware of. -
lmiguelvargasf about 6 years@stevenVascellaro, you can check this link. Or you could find where
pylint
got installed in your machine. -
lkraider almost 6 yearsSee my answer regarding the correct output filter to detect the column as well: stackoverflow.com/a/50298934/324731
-
ub_marco almost 6 years@lkraider I don't see the relevant difference. You're separating line and column by comma which I tried - it didn't work. Then you're escaping the colon which shouldn't be necessary. I tried your full solution for
msg-template
andOutput filters
but the column was not detected. Maybe something else is wrong, can you pinpoint the problem? I'm working with PyCharm 2018.1.2. -
lkraider almost 6 yearsHow are you testing the detection? Mine doesn't underline the line number like yours (nor the column), but clicking the link moves the caret to the correct position.
-
lkraider almost 6 yearsI found the issue, indeed if the line number is shown with underline, the link will not work. This would happen in my example when the line is >99. When there is a space separation, the link will correctly place the caret at the column position.
-
geometrikal almost 6 yearsThese settings work on Windows too in case anyone was wondering.
-
Aaron F over 5 yearsThis looks good. Unfortunately it's throwing an exception on startup - it doesn't like the version of pylint installed in /usr/bin and isn't using pylint from the project's virtualenv. I'll keep checking for updates, because your plugin looks like it'll be the ideal solution :-)
-
Roberto Leinardi over 5 years
-
Aaron F over 5 yearsI had a quick look and it seems to be a duplicate of #29. I'll add the relevant lines from my log to that issue.
-
Gautam Jain over 5 years@AaronF You would need to manually set the path of the pylint to the one installed on your virtualenv. eg.: projectvenv/bin/pylint instead of /usr/bin/pylint
-
JohnEye over 5 yearsWhile this answer works, it just writes the results to a text field. There is now a PyCharm plugin that does all that and also hooks into the IDE and highlights suspicious lines. It can be downloaded from the default repository. See one of the other answers for details.
-
limonik over 5 yearsI made every step that you described but I got warning message: No config file found, using default configuration. Then I created a resource file as in an answer : stackoverflow.com/questions/5253559/…. Now pylint is working good.
-
joel.wilson almost 4 yearsThis works like a charm; just one question - Can we get a pylint score for each individual file via this method? Kind like a report
-
StackGuru over 3 years@lmiguelvargasf : What are Program, Parameters & Working directory here ? Currently, I am executing as "python test.py --var1=xyz". How do I configure Program, Parameters & Working directory accordingly ?
-
Dan Ciborowski - MSFT over 3 yearsThis used to work for me.... now I get "Windows cannot find 'file:///C:\Use...".
-
Charlie about 3 yearsCurrently this plug in has some issues, see github.com/leinardi/pylint-pycharm/issues/76