Installing Pylint for Python3 on Ubuntu

Python 2 and 3 are separate beasts. If you install a script into the site-packages of one version, you are not installing it into the other.

I'd install it through pip, but you'll need the right version of pip.

sudo apt-get install python3-pip
sudo pip-3.3 install pylint

This will replace your 2.7 version. We can confirm this by checking less $(which pylint):

#!/usr/bin/python3.3
# EASY-INSTALL-ENTRY-SCRIPT: 'pylint==1.0.0','console_scripts','pylint'
__requires__ = 'pylint==1.0.0'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pylint==1.0.0', 'console_scripts', 'pylint')()
    )

@sayth 's comment to the accepted answer was what drew me here -- I write both python 2 and python 3 scripts, and I want to be able to check either against the correct ruleset. installing pylint using pip3 install pylint writes a short script to /usr/local/bin which invokes the python3 interpreter, and seems, therefore to assume all files to be checked are python 3 scripts.

to work around this, I now have the following files:

~/bin/pylint2:

#!/usr/bin/python2
# EASY-INSTALL-ENTRY-SCRIPT: 'pylint','console_scripts','pylint'
__requires__ = 'pylint'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pylint', 'console_scripts', 'pylint')()
    )

and ~/bin/pylint3:

#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'pylint','console_scripts','pylint'
__requires__ = 'pylint'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pylint', 'console_scripts', 'pylint')()
    )

and then, because I like to use pylint directly from Geany's "Build Commands" menu, and I can't specify different commands for python 2 and python 3 scripts, i also have ~/bin/pylint:

#!/bin/bash
if [[ $(head -n 1 "${@: -1}") == *python3* ]]
then
    # python3 file
    pylint3 "$@"
else
    pylint2 "$@"
fi

which dispatches the correct version by sniffing the shebang.

Not perfect, certainly, but functional and, perhaps, useful for others.


The pylint ecosystem has changed since (after this question was asked), and there is now a separate pylint for python3. It can be installed with:

sudo apt install pylint3

Worked for me on Ubuntu 16.04.2 LTS

Tags:

Python