Using pip in python : Python tutorial 29

What is pip :

pip is a package management system , we can use it to install and manage software packages in python. pip is included by default for python 2.7.9 and later . For python3, it is called pip3 which is also included by default for Python 3.4 and later .

Installing pip :

pip is already installed for python >=2.7.9 or for python3 >=3.4 . First check your python version using python -V ( V is capital V) . If your version doesn’t belong to any of the above versions, then you need to install pip manually from this site  .

Using pip :

Before using pip, check its version number first using pip -V . If it is showing some output, that means the installation is successful.

Install a package using pip :

Suppose, we want to install package “Pillow” ( image processing library ) using pip. We need to use the following command for installing it :

pip install Pillow

Install specific version of a package :

The versions of “Pillow” is mentioned here  . If we want to install only 4.1.1 version, then we should use the following command :

pip install Pillow==4.1.1

Specify a minimum version of a package :

We can also specify a minimum version number for a package . If it is not available, pip will install the latest version.

pip install Pillow>=4.1.1

Search for a package :

You can search for a specific package or similar packages using search command :

pip search Pillow

It will search for all packages similar to “Pillow” and list it down . Mainly it will check for libraries with name or description containing “Pillow” keyword

Upgrade package :

Upgrade a installed package :

pip install —upgrade name_of_the_package

Get details of a installed package :

Get details of a package using the below command :

pip show name_of_the_package

List all installed package :

You can build the list of all the installed packages and version numbers using freeze command . The output can also be redirect to a text file file :

pip freeze > requirements.txt

Install packages from a file :

We can also put all the list of packages in a text file like we have done above for “requirements.txt” and install all of them at once using -r or —requirement flag :

pip install -r requirements.txt

List all outdated packages using pip :

For pip version 1.3 and above, you can check for outdated packages installed and latest version available :

Uninstalling a package :

To uninstall a package (for this example, we will uninstall Pillow) , use the bellow command :

pip uninstall Pillow


Leave a Reply