PIP#

Pip (Package Installer for Python) is the primary way to install packages into Python environments.

Pip is a Python package, so you can access it through the interpreter. However, it is more commonly used as a command-line tool. Check corresponding documentation.

Setup#

This notebook obviously uses many pip features. To prevent editing the global configuration and avoid corresponding warnings in the command outputs, it is reasonable to use a separate environment for the examples in this notebook. Run the following code to create a new Python environment and activate it. After that, any command you run will be executed in the separate environment.

python -m venv /tmp/pip_env
source /tmp/pip_env/bin/activate
which pip
/tmp/pip_env/bin/pip

Status#

Consider some commands that allow you to check the current state of packages in your environment.


The following cell shows how you can check information about the pip version currently in use.

pip --version
pip 24.3.1 from /tmp/pip_env/lib/python3.12/site-packages/pip (python 3.12)

To show currently installed packages, use pip list.

pip list
Package Version
------- -------
pip     24.3.1

You can check details about a package using the syntax pip show <package name>. The following cell applies pip show to pip itself, as it is still a Python package.

pip show pip
Name: pip
Version: 24.3.1
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: 
Author-email: The pip developers <distutils-sig@python.org>
License: MIT
Location: /tmp/pip_env/lib/python3.12/site-packages
Requires: 
Required-by: 

Install/uninstall#

The main goal of pip is to install packages. Sometimes you also need to remove installed packages. To perform these tasks, use:

  • pip install for package installation.

  • pip uninstall for package uninstallation.


The following cell installs the hello-world package into the active Python environment.

pip install hello-world
Collecting hello-world
  Using cached hello_world-0.2-py3-none-any.whl
Installing collected packages: hello-world
Successfully installed hello-world-0.2

[notice] A new release of pip is available: 24.3.1 -> 25.0
[notice] To update, run: pip install --upgrade pip

So you can find hello-world in the list of pacakges.

pip list | grep hello-world
hello-world 0.2

The next command removes the hello-world package.

pip3 uninstall -y hello-world
Found existing installation: hello-world 0.2
Uninstalling hello-world-0.2:
  Successfully uninstalled hello-world-0.2

Now, the hello-world package no longer appears in the pip list output.

pip3 list | grep hello-world | true

Download#

With pip download, you can download a package without installing it.


The following cell downloads python-dotenv to the /tmp/pip_download directory.

mkdir /tmp/pip_download
pip3 download --destination-directory /tmp/pip_download/ python-dotenv
Collecting python-dotenv
  Using cached python_dotenv-1.0.1-py3-none-any.whl.metadata (23 kB)
Using cached python_dotenv-1.0.1-py3-none-any.whl (19 kB)
Saved /tmp/pip_download/python_dotenv-1.0.1-py3-none-any.whl
Successfully downloaded python-dotenv

Now there is a corresponding .whl file that represents the downloaded package.

ls /tmp/pip_download
python_dotenv-1.0.1-py3-none-any.whl