How to Install PIP in Python?

Learn via video course
FREE
View all courses
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Topics Covered

Package Installer for Python which is known as PIP is the standard package manager for python. Ian Bicking created a tool to manage and install libraries in python called pyinstall in 20082008. The pyinstall was renamed to PIP Package Management System in 20112011 when Ian handed over the maintenance of pyinstall to Python Packaging Authority (PyPA).

PIP is the most popular and most used package manager for Python. PIP is a command line tool to install, update and remove libraries in Python.

PIP is shipped along with the Python installer itself. But if you missed it, we'll help you install pip in an existing python installation.

Getting Started

Firstly we will verify if a python installation is already present. To do this in windows, run the following command in powershell(or command prompt).

The above is the python shell. It shows that the python installation is available on your system.

Instead, if you are shown an error saying

It means python is not properly installed on your system, or you need to update $PATH environment variable with the location of python binaries. Follow the tutorial Install Python on Windows to resolve the above error.

Installing pip in Python

To install pip in python, we can follow either of the following two methods:

  1. Installing PIP using theensurepipmodule or
  2. Installing PIP usingget-pip.py

Installing PIP Usingensurepip

Python has a pre-installed module named ensurepip. This module helps us to install pip and update it for any python installation or a virtual environmeint.

To install pip using this module run the following command in PowerShell or Command Prompt.

The advantage of using ensurepip module is that the installation of pip does not require us to have an internet connection. The ensurepip module itself contains all the components needed to install pip.

To always install the latest version of pip using ensurepip, we may pass --upgrade option to the above command.

Another method of installing pip that requires an active internet connection is by using get-pip.py.

Installing PIP Using get-pip.py

This method uses a python script called get-pip.py to install pip in python. This script is officially published by PyPA, which lets one download pip and install it in any python installation or virtual environment.

Follow the below steps to start installing pip in python:

Step 1: Downloadingget-pip.pyFile

This method uses a python script called get-pip.py to install pip in python. This script is officially published by PyPA, enabling one to download pip and install it in any python installation or virtual environment.

Make sure you have an active internet connection. Then visit the URL https://bootstrap.pypa.io/get-pip.py" using any browser to download the get-pip.py file.

You may run the following commands in PowerShell to download the file using the command line.

After using either of the two ways to download the get-pip.py file, open the directory where the file is located in PowerShell.

Step 2: Executingget-pip.pyto install pip

As we have already verified the python installation. We will use the python command to execute the script get-pip.py.

Step 3: Verifying the pip installation

The above command will display the error, if any, in the output. On successful installation message saying Successfully installed pip-XX.X.X will appear at the end.

Since humans are hungry for perfection, we can run the below command to ensure the pip has been installed properly.

Output with the installed version number of pip will appear on the command line.

Upgrading PIP

There can be a situation where an existing installation of pip needs to be updated. Having the latest version of pip ensures that all the repositories of python libraries are updated before we fetch and install any new library.

There is no auto-updating feature available for pip(or even python), so we have to trigger the update of pip manually.

Run the command below in PowerShell to upgrade an existing installation of pip.

A success message is given at the end of the upgrade.

Note: That upgrading pip also requires an active internet connection.

Learn More:

Here are a few references that will help you to get more insights regarding pip.

Conclusion

In this tutorial, we have understood the following:

  • How to install pip in python on windows
  • Using the ensurepip module to install pip
  • ensurepip can work without an active internet connection
  • Using get-pip.py script to install pip in python
  • get-pip.py method needs you to have an active internet connection to work
  • pip lacks the auto-update feature and had to be updated manually