For the latest versions of pylint
, tested in Aug. 2023
Tested on Ubuntu 22.04.
New instructions:
See: https://github.com/PyCQA/pylint#install
pip3 install pylint
# upgrade to the latest version; see:
# https://stackoverflow.com/a/47071257/4561887
pip3 install pylint --upgrade
Old instructions are below this point:
This answer completely rewritten since the downvote. Tested in Ubuntu 18.04.
pylint
versions before 2.0.0 or so have separate executables for Python2 vs Python3 code. pylint
is for Python2 and pylint3
is for Python3. As of version 2.0.0 or so, we are back to one executable named pylint
, and it handles only Python3 code. To get this latest version from the GitHub releases page, see Option 1 below.
Summary
Option 1 is recommended. Option 2 works, but is obsolete.
- Option 1: See "Option 1 Installation steps" below.
To get the latest version of
pylint
for Python3, you must manually download the latest release from GitHub, extract it, and then run this to install it:
# Install it
sudo python3 setup.py install
# Check its version
pylint --version
The version will be pylint 2.12.2
or later and the executable for Python3 will be called pylint
. There is no executable for Python2, since Python2 is obsolete and has been "sunset", or deprecated, since 1 Jan. 2020.
This version of pylint
shows code numbers for problems it finds in your code, such as C0301
or W0105
, as shown below.
- Option 2: See "Option 2 Installation steps" below.
- To get an older version of
pylint
, such as pylint 1.9.2
, which works only on Python2 code, do this:
# Install it
sudo apt update
sudo apt install pylint
# Check its version
pylint --version
- To get an older version of
pylint3
, such as pylint3 1.8.3
, which works only on Python3 code, do this:
# Install it
sudo apt update
sudo apt install pylint3
# Check its version
pylint3 --version
- These older versions have separate executables for Python2 and Python3 code, and they do NOT show code numbers for problems they find in your code. For these older versions, use
pylint
for Python2 code and pylint3
for Python3 code.
Details
Resources:
- GitHub source code: https://github.com/PyCQA/pylint
- Pylint User Manual: https://pylint.pycqa.org/en/latest/
- Tutorial: https://pylint.pycqa.org/en/latest/tutorial.html. Notice that the
pylint
output shows these 5 types of messages (emphasis added):
Output:
Using the default text output, the message format is :
MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE
There are 5 kind of message types :
- (C) convention, for programming standard violation
- (R) refactor, for bad code smell
- (W) warning, for python specific problems
- (E) error, for probable bugs in the code
- (F) fatal, if an error occurred which prevented pylint from doing
further processing.
[RECOMMENDED] Option 1: Install the latest version of pylint
(version 2.12.2 or later; from the GitHub repo) for Python3 on Ubuntu
This should work on any version of Ubuntu I believe. Tested on Ubuntu 18.04. For best results and to get the latest version of pylint
for Python3, these are the installation steps I recommend you follow.
Sample pylint --version
information (for Python3) after following these steps:
pylint 2.12.2
astroid 2.9.3
Python 3.6.9 (default, Dec 8 2021, 21:08:43)
[GCC 8.4.0]
Sample usage command and output. Notice it does show the C
onvention and W
arning codes, which is great!:
eRCaGuy_hello_world/python$ pylint hello_world.py
************* Module hello_world
hello_world.py:4:0: C0301: Line too long (102/100) (line-too-long)
hello_world.py:33:0: C0116: Missing function or method docstring (missing-function-docstring)
hello_world.py:49:-1: W0105: String statement has no effect (pointless-string-statement)
-----------------------------------
Your code has been rated at 4.00/10
Option 1 Installation steps:
- Go to the "Releases" page for
pylint
on GitHub, and download the source code for the latest release (ex: v2.12.2).
- In your file manager, right-click on the downloaded file and go to "Extract Here". This will produce a directory named
pylint-2.12.2
, for instance.
cd
into the extracted directory and run the setup.py
script; ex:
cd path/to/pylint-2.12.2
sudo python3 setup.py install
See also: https://github.com/PyCQA/pylint#install
- Check your version and ensure it now says
pylint 2.12.2
pylint --version
- Lint some code:
pylint path/to/my_python3_file.py
pylint
is a Python file itself. which pylint
shows it is located in /home/gabriel/.local/bin/pylint
. Running cat "$(which pylint)"
shows what it contains:
$ cat "$(which pylint)"
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pylint import run_pylint
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(run_pylint())
Option 2: Install an obsolete version of pylint
(from the Ubuntu apt
repositories) for Python2 and Python3 on Ubuntu
This should work on Ubuntu 16.04 or later, I believe. Tested on Ubuntu 18.04.
Sample pylint --version
information (for Python2 only) after following these steps:
No config file found, using default configuration
pylint 1.9.2,
astroid 1.6.6
Python 2.7.17 (default, Feb 27 2021, 15:10:58)
[GCC 7.5.0]
Sample pylint3 --version
information (for Python3 only) after following these steps:
No config file found, using default configuration
pylint3 1.8.3,
astroid 1.6.0
Python 3.6.9 (default, Dec 8 2021, 21:08:43)
[GCC 8.4.0]
Sample usage command and output. Notice it does NOT show the C
onvention and W
arning codes, because this version is obsolete!:
eRCaGuy_hello_world/python$ pylint3 hello_world.py
No config file found, using default configuration
************* Module hello_world
C: 4, 0: Line too long (102/100) (line-too-long)
C: 33, 0: Missing function docstring (missing-docstring)
W: 49,-1: String statement has no effect (pointless-string-statement)
Option 2 Installation steps:
# Update apt repositories
sudo apt update
# Install `pylint` for Python2
sudo apt install pylint
# Install `pylint3` for Python3
sudo apt install pylint3
Now you can use them to check your Python2 and Python3 files:
# python2
pylint path/to/my_python2_file.py
# python3
pylint3 path/to/my_python3_file.py
The pylint
and pylint3
executables are actually Python scripts themselves. Check out their executable paths and what they contain:
eRCaGuy_hello_world/python$ which pylint
/usr/local/bin/pylint
eRCaGuy_hello_world/python$ which pylint3
/usr/bin/pylint3
eRCaGuy_hello_world/python$ cat "$(which pylint)"
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pylint import run_pylint
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(run_pylint())
eRCaGuy_hello_world/python$ cat "$(which pylint3)"
#! /usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'pylint==1.8.3','console_scripts','pylint'
__requires__ = 'pylint==1.8.3'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('pylint==1.8.3', 'console_scripts', 'pylint')()
)
pylint
versions before 2.0.0 or so have separate executables for Python2 vs Python3 code.pylint
is for Python2 andpylint3
is for Python3. As of version 2.0.0 or so, we are back to one executable namedpylint
, and it handles only Python3 code. To get this latest version from the GitHub releases page, see my answer I just added here.