15.5 C
Amsterdam
angeloma
Senior Writer and partner

Install Pylint on Ubuntu 20.04

Hello, friends. If you are a Python developer then you should know how to install PyLint on Ubuntu 20.04. This tool adds an extra layer to help the developer to have clean and bug-free code.

What is PyLint?

According to the PyLint website:

Pylint is a Python static code analysis tool which looks for programming errors, helps enforcing a coding standard, sniffs for code smells, and offers simple refactoring suggestions.

It’s highly configurable, having special pragmas to control its errors and warnings from within your code, as well as from an extensive configuration file. It is also possible to write your plugins for adding your checks or for extending pylint in one way or another.

One of the great advantages of using PyLint is that it is open-source and free. So you can include it in a wide variety of projects. Also, it integrates seamlessly with many popular IDEs so you can use it without any problems. Moreover, you can use it as a standalone application to increase the flexibility of your application.

- Advertisement -

Some of the main features are:

  • Error detection so you can further refine the code you write.
  • Fully customizable The main configuration is in a text file that you can configure to your liking.
  • Continuous integration This means that PyLint can be integrated with tools like Jenkins or Hudson.

And many more…

PyLint for its analysis uses Python PEP8 so we are talking about almost a standard in the development with this language.

So, let’s start.

Install PyLint on Ubuntu 20.04

The installation is quite simple for the powerful and useful tool. So, open a terminal and as always, update the entire distribution.

sudo apt update
sudo apt upgrade

Now install some Python tools like PIP. I imagine you already have it installed, but still, in case you don’t, just in case you do not.

sudo apt install python3-pip python3-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libc-dev-bin libc6-dev libcrypt-dev libexpat1-dev libpython3-dev libpython3.8 libpython3.8-dev libpython3.8-minimal libpython3.8-stdlib linux-libc-dev
  python-pip-whl python3-wheel python3.8 python3.8-dev python3.8-minimal zlib1g-dev
Suggested packages:
  glibc-doc manpages-dev python3.8-venv python3.8-doc binutils binfmt-support
Recommended packages:
  manpages-dev build-essential
The following NEW packages will be installed:
  libc-dev-bin libc6-dev libcrypt-dev libexpat1-dev libpython3-dev libpython3.8-dev linux-libc-dev python-pip-whl python3-dev python3-pip python3-wheel python3.8-dev
  zlib1g-dev
The following packages will be upgraded:
  libpython3.8 libpython3.8-minimal libpython3.8-stdlib python3.8 python3.8-minimal
5 upgraded, 13 newly installed, 0 to remove and 66 not upgraded.
Need to get 16.9 MB of archives.
After this operation, 52.0 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Before using PIP then it’s a good idea to update it so you don’t have any problems with it. So, you can do it in the following way:

pip3 install -U pip

Check the installed version of PIP with the command:

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

Now you can install PyLint by running the following command:

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

This will install it and to check the installed version you just need to run

pylint --version

Output

pylint 2.9.3
astroid 2.6.2
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
GCC 9.4.0

Now yes, the tool is installed without problems.

Basic use of PyLint

The program has a very simple terminal interface that allows us to use it without any problems.

The basic usage is as follows

pylint [options] modules_or_packages

It is also possible to analyze Python files, with a few restrictions

pylint mymodule.py

It is also possible to call Pylint from another Python program

import pylint.lint
pylint_opts = ['--version']]
pylint.lint.Run(pylint_opts)

In this way, we can analyze our code, and using the screen output you will be able to notice the necessary changes. An example of how the screen output of the application looks like is as follows

file.py:1:0: W0301: Unnecessary semicolon

So you have to update it and fix what you need to do.

Conclusion

In this post, you have met a very useful tool in Python development that we can take advantage of quickly and easily by installing it.

Enjoy it

- Advertisement -

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Donate to Osradar

Latest article