How to Install Pylint on Ubuntu 20.04

When we develop an application, we need code analyzers to help us debug errors and tell us where we have made mistakes. Well, Python has a significant tool, and today you will learn how to install it. In short, this post is about how to install PyLint on Ubuntu 20.04.

First, what is PyLint?

PyLint is a code parser for python that helps developers to check python code for syntax errors and so on.

One of the main features of Pylint is that we can integrate it into many text editors such as Eclipse, Emacs, TexMate VIM and so on.

The great advantage of Pylint is that it is highly configurable, customizable, and you can easily write a small plugin to add a personal feature.

As you would expect, it is open source and available for many systems and for many projects.

One thing that not many people know is that Pylint ships with Pyreverse which creates UML diagrams for python code. In other words, we can create UML quickly and all integrated into the language.

There are many more things that we can know if we visit the website of this application.

Install PyLint on Ubuntu 20.04

There are two ways to install PyLint. One of them is through the official repositories of the distribution. This method is effortless and ideal for newbies.

The only thing you have to do is open a terminal and execute this couple of commands

sudo apt update
sudo apt install pylint

Thereafter, you will be able to use it without any problems.

This method is easy to do but does not provide us with the latest stable version of the tool.

Install PIP (Python Package Manager) on Ubuntu 20.04

The best way to install PyLint is through PIP. So first open a terminal in your system and update the whole system.

sudo apt update
sudo apt upgrade

Then, install PIP as follows.

sudo apt install python3-pip python3-dev

Before using PIP, it is recommended to update it.

pip3 install -U pip

Now verify the version of PIP you are running

pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

Now add the folder where PIP saves the binaries to the PATH.

nano ~/.bashrc

And at the end of the file it adds.

export PATH=$PATH:/home/user/.local/bin

Finally apply the changes

source ~/.bashrc

Installing PyLint

With PIP already on the system, we can then install PyLint. To do so, just run.

pip3 install pylint

This way you will have it on the system. Before using it, it’s a good idea to update it.

pip3 install -U pylint 

If you want it, you can show the version that has been installed with the following command.

pylint --version

Sample Output

pylint 2.12.2
astroid 2.9.3
Python 3.8.10 (default, Nov 26 2021, 20:14:08) 
[GCC 9.3.0]
Pylint on Ubuntu 20.04
Pylint on Ubuntu 20.04

First steps with PyLint

The basic syntax with which you can use PyLint is as follows

pylint [options] modules_or_packages

It is also possible to parse Python files, with some restrictions. The thing to keep in mind is that Pylint will attempt to convert the filename to a module name, and will only be able to process the file if it succeeds.

pylint mymodule.py

It is also possible to call Pylint from another Python program, thanks to the Run() function in the pylint.lint module (assuming the Pylint options are stored in a list of pylint_options strings) like:

import pylint.lint
pylint_opts = ['--disable=line-too-long', 'myfile.py']
pylint.lint.Run(pylint_opts)

Remove Pylint in Ubuntu 20.04

If you prefer not to use PyLint anymore, you can remove it from the system. The procedure is simple but will depend on the installation method you have chosen.

If you have installed it via APT in the first method, then to uninstall it you have to run

sudo apt remove pylint

In case you installed it with PIP then you have to run

pip3 remove pylint

This way there will be no trace of the application left on the system.

Conclusion

Developing applications is not as easy as many people make it out to be, it is quite complicated. Thanks to tools like PyLint we can analyze our code to find bugs that prevent it from building properly.

Share this post and help us to grow.

Share This:

Leave a Comment

Your email address will not be published. Required fields are marked *