pip-install
Install Python packages
TLDR
Install a package
Install a specific version of a package
Install packages listed in a file
Install packages from an URL or local file archive (.tar.gz | .whl)
Install the local package in the current directory in develop (editable) mode
SYNOPSIS
pip install [options]
pip install [options] -r
pip install [options] -e
pip install [options]
PARAMETERS
package
Specifies the name of the package to install. Can include version specifiers like package==1.0 or package>=1.0.
-r
Install packages listed in the given requirements file. Each line in the file specifies a package.
-e
Install a project in editable mode (for development). This creates a link to the source code.
--upgrade, -U
Upgrade all specified packages to the newest available version.
--force-reinstall
Reinstall all packages even if they are already installed and up-to-date.
--user
Install packages into the user's site-packages directory instead of the system-wide one.
--target
Install packages into the specified directory.
--no-deps
Do not install package dependencies.
--no-cache-dir
Disable the pip cache.
--index-url
Base URL of the Python Package Index (default is PyPI).
--extra-index-url
Additional URLs to search for packages.
DESCRIPTION
The pip install command is the primary method for installing Python packages from the Python Package Index (PyPI) or other package indexes. It automates the process of downloading, building (if necessary), and installing Python libraries and their dependencies, making it simple for developers to manage project requirements. pip resolves dependencies recursively, ensuring all necessary components are installed. It supports various installation sources, including PyPI, version control systems, local directories, and distribution archives. When used with a requirements.txt file, pip install can install multiple packages at once, making project setup consistent and reproducible. It's an essential tool in the Python ecosystem for setting up development environments and deploying applications.
CAVEATS
pip install can lead to issues if not used carefully. Installing packages globally (without a virtual environment) can cause conflicts between different projects requiring different versions of the same package. It's highly recommended to use virtual environments (e.g., venv or conda) to isolate project dependencies. Installing directly from untrusted sources can pose security risks. Dependency resolution can sometimes be complex, leading to version conflicts, especially when multiple packages depend on different versions of a common library.
<B>VIRTUAL ENVIRONMENTS BEST PRACTICE</B>
Always use virtual environments (e.g., python -m venv .venv) for new Python projects. This isolates project dependencies, preventing conflicts with other projects or system-wide Python installations. Activate the environment (source .venv/bin/activate on Linux/macOS, .venv\Scripts\activate on Windows) before using pip install.
<B>REQUIREMENTS FILES</B>
Use pip freeze > requirements.txt to save a list of your project's exact dependencies. This allows others to install the same versions with pip install -r requirements.txt, ensuring consistent environments.
HISTORY
pip (short for "Pip Installs Packages" or "Preferred Installer Program") emerged as a replacement for easy_install in 2008. It was developed by Ian Bicking, who also created virtualenv and setuptools. pip quickly gained popularity due to its improved dependency resolution, easier uninstallation of packages, and support for requirements.txt files, which easy_install lacked. It became the recommended package installer for Python and has been included with Python distributions since Python 3.4. Its development has continued to evolve, adding features like wheel support and a more robust resolver.