Installing and Using pip on Windows, Linux and macOS

pip is a tool written in Python to facilitate the download and installation of packages hosted in the Python Package Index (PyPI). It runs on all major platforms: Microsoft Windows, Linux and macOS; CPython 2.6+, 3.x and PyPy.

Before using pip, make sure it is installed. Open the terminal and run:

$ python -m pip --version

Windows users might also use:

> py -m pip --version

If you get no error, then jump directly to the last section to learn how to use this tools to download, install and upgrade packages. Otherwise continue reading.

Installing on Windows, Linux and macOS

First, download the installer file from this link. If your browser shows the file content instead of downloading it, press CTRL + S to save it in your computer. Then open a terminal where the get-pip.py file lies and execute the following command:

$ python get-pip.py

Or in Windows:

> py get-pip.py

You can also use the full file path.

Linux/macOS:

$ python Downloads/get-pip.py

Windows:

> py Downloads\get-pip.py

You will get an output like the following:

Downloading/unpacking pip
Downloading/unpacking setuptools
Installing collected packages: pip, setuptools
Successfully installed pip setuptools
Cleaning up...

Finally, ensure pip was installed successfully by running in the terminal.

Linux/macOS:

$ py -m pip --version

Windows:

> py -m pip --version

Which should print something like this:

pip 21.2.3 from C:\Python39\lib\site-packages\pip (python 3.9)

Installing on Debian / Ubuntu / Fedora

Although installing from source is the preferred way, if you use Debian or Ubuntu you can also use apt-get to download and install pip in a quick and simple way. Run this command on the terminal:

$ sudo apt-get install python-pip

In Fedora, use yum instead:

$ sudo yum install python-pip

Upgrading to the latest version

If you have already installed pip but want to update it to its latest version, you will need to run the following command.

On Linux and macOS:

$ python -m pip install -U pip

On Windows:

> py -m pip install -U pip

How to use pip

To install a package from PyPI use the following command (prepend py -m or python -m accordingly):

pip install package

Where package is the name of a module, library, <em>script</em> or <em>framework</em> found in https://pypi.org/. For example:

$ python -m pip install django
Downloading/unpacking django
Installing collected packages: django
Successfully installed django
Cleaning up...

Or on Windows:

> py -m pip install django

Package names are case insensitive.

To uninstall a package, use:

pip uninstall package

For example:

$ pip uninstall django
...
Proceed (y/n)? y
Successfully uninstalled Django

To list installed packages (even those not obtained installed via pip) use:

pip list

For example:

$ pip list
autopy (0.51)
pips (1.5.4)
putil (0.6.1)
pyodbc (3.0.7)
setuptools (3.4.4)
Twisted (13.2.0)
uptime (3.0.1)
zope.interface (4.1.0)

Additionally, --outdated can be used in conjunction with the list command to determine which of the installed packages are out of date:

$ pip list --outdated
zope.interface (Current: 4.1.0 Latest: 4.1.1)

Finally, to display information about an installed package:

$ pip show zope.interface
---
Name: zope.interface
Version: 4.1.0
Location: C:\Python27\lib\site-packages
Requires: setuptools

These are the basic pip commands for installing and removing packages. You can visit the official user guide for deeper and more detailed information.

Comments