Install uninstall and manage Python packages with pip

Introduction

The power of Python is the very large amount of libraries that are available online. These libraries can be downloaded to your development environment as packages. Libraries installed on your system system are gradually accumulating and their management could be problematic if there were no adequate tools.

The package management in Python can be really an easy thing if you use the right tools and Pip is one of them.

All the packages used by the community of developers in Python are collected for years in a single repository called PyPI (Python Package Index). In this repository, all packages are sorted, documented and versioned with a suitable control for all dependencies.

PIP is an essential tool that allows you to download, update (synchronize virtually) all of the repository packages you need, taking care to check the proper dependencies and the compatibility among versions

Pip installation

Generally in most distributions of Python, pip should already be included. In fact, for all versions of Python 2> 2.7.9 and Python 3> 3.4, pip is already installed. Same thing if you have created a virtual environment with virtualenv or pyenv.

Installation is simple

On Ubuntu and Debian

1

2

$sudo apt-get install python-pip

On Fedora

1

2

$sudo yum install python-pip

On Mac

1

2

$sudo easy_install pip

But if it were not so, you can install it by downloading a script in Python specially created and then run it.

1

2

3

wget https://bootstrap.pypa.io/get-pip.py

python get-pip.py

Using PIP – Commands

Pips, in addition to being very useful, it is also very simple to use. From the command line, Just write pip followed by an option (command) which is nothing but the task that we want him to do.

Installing a package

For example, to install a package, simply write

1

2

pip install nomepacchetto

Pip will connect with the repository, then perform a search to find the package you requested. It will check if there is a version compatible with your version of Python and with the operating system you are using.

Then it will ask you for confirmation if you want to install with classic choice Yes or No. Then if confirm the installation will begin to install the package and any other packages which are required for its operation.

Uninstall a package

Removing a package is even easier

1

2

pip uninstall nomepacchetto

List installed packages

To get the list of installed packages on your system

1

2

pip freeze

or

1

2

pip list

Search for a particular package in the repository PyPI

Finally if you want to know both the existence and the information of a given packet within the PyPI repository without having to install it, you write the following command:

1

2

pip show nomepacchetto

update PIP

However Python is a language that is experiencing great excitement and then every month there are always a number of new releases, including PIP. So it is important to check if PIP itself is upgraded to the latest version