pip
In Python, pip
is the default package installer and dependency manager. It allows you to install and manage additional libraries and dependencies that aren’t part of the Python standard library.
When you want to use a package that’s not included with Python, pip
downloads and installs it from the Python Package Index (PyPI).
The name “pip” is commonly understood to be a recursive acronym for “pip installs packages,” though some suggest it was simply chosen because it’s a short, memorable word. Originally released in 2008, pip replaced the older easy_install
as Python’s primary package installation tool.
Basic usage involves commands like:
pip install <package_name>
- Installs a packagepip uninstall <package_name>
- Removes a packagepip list
- Shows installed packagespip freeze
- Outputs installed packages in requirements format
Additionally, pip
can handle the installation of packages listed in a requirements.txt
file, which is particularly useful for sharing project dependencies in a collaborative environment.
Pip is typically included with Python installations from version 3.4+ but can be installed separately if needed. It integrates with virtual environments and supports installing packages from various sources including PyPI, version control systems, local directories, and wheels.
Example
Here’s how you can use pip
to install a package from PyPI. Say you want to install the popular requests
library, which is used for making HTTP requests:
$ pip install requests
In this command, pip
fetches the requests
package from PyPI and installs it in your Python environment. You can then import the package in your code and use it as demonstrated:
>>> import requests
>>> response = requests.get('https://api.github.com')
>>> response.status_code
200
In this example, you import the requests
and make a GET request to the GitHub API. You get a status code of 200
, meaning that the API is available.
Related Resources
Tutorial
Using Python's pip to Manage Your Projects' Dependencies
What is pip? In this beginner-friendly tutorial, you'll learn how to use pip, the standard package manager for Python, so that you can install and manage packages that aren't part of the Python standard library.
For additional information on related topics, take a look at the following resources: