The PyPA recommended tool for installing Python packages.
91
Comprehensive package installation capabilities including dependency resolution, version control integration, and support for multiple package sources and formats.
Install packages from PyPI with automatic dependency resolution.
# Install latest version
pip install package_name
# Install specific version
pip install package_name==1.2.3
# Install version with constraints
pip install "package_name>=1.0,<2.0"
pip install "package_name~=1.2.0" # Compatible release
# Install multiple packages
pip install package1 package2 package3Install packages from requirements files with dependency locking and constraint handling.
# Install from requirements file
pip install -r requirements.txt
# Install from multiple requirements files
pip install -r requirements.txt -r dev-requirements.txt
# Install with constraints
pip install -r requirements.txt -c constraints.txtRequirements file format:
# Direct dependencies
requests==2.28.1
django>=4.0,<5.0
# VCS dependencies
git+https://github.com/user/repo.git@v1.0#egg=package_name
# Local dependencies
-e ./local_package
/path/to/local/package.tar.gz
# Index options
--index-url https://pypi.org/simple/
--extra-index-url https://test.pypi.org/simple/
# Installation options
--no-deps
--force-reinstallInstall packages directly from version control repositories with branch, tag, and commit support.
# Git repositories
pip install git+https://github.com/user/repo.git
pip install git+https://github.com/user/repo.git@branch_name
pip install git+https://github.com/user/repo.git@tag_name
pip install git+https://github.com/user/repo.git@commit_hash
# With subdirectory
pip install "git+https://github.com/user/repo.git#subdirectory=pkg_dir"
# With specific name
pip install "git+https://github.com/user/repo.git#egg=package_name"
# SSH URLs
pip install git+ssh://git@github.com/user/repo.git
# Other VCS systems
pip install svn+https://svn.example.com/repo/trunk/
pip install hg+https://bitbucket.org/user/repo
pip install bzr+https://launchpad.net/user/repoInstall packages from local files, directories, and development installations.
# Install from local directory
pip install /path/to/package/
# Install from archive
pip install /path/to/package.tar.gz
pip install /path/to/package.whl
# Editable/development installation
pip install -e /path/to/package/
pip install -e . # Current directory
# Install from URL
pip install https://example.com/package.tar.gzControl installation behavior with various options and flags.
# Installation modes
pip install --user package_name # User installation
pip install --system package_name # System installation
pip install --target /path/to/dir package_name # Target directory
# Dependency handling
pip install --no-deps package_name # Skip dependencies
pip install --force-reinstall package_name # Force reinstall
pip install --upgrade package_name # Upgrade to latest
pip install --upgrade-strategy eager package_name # Upgrade dependencies
# Build options
pip install --no-binary :all: package_name # Build from source
pip install --only-binary :all: package_name # Only use wheels
pip install --prefer-binary package_name # Prefer wheels
pip install --no-build-isolation package_name # Disable build isolation
# Index options
pip install --index-url https://pypi.org/simple/ package_name
pip install --extra-index-url https://test.pypi.org/simple/ package_name
pip install --trusted-host pypi.org package_name
pip install --find-links /path/to/dir package_name
# Caching
pip install --no-cache-dir package_name # Disable cache
pip install --cache-dir /path/to/cache package_name # Custom cache
# Verbosity and output
pip install --verbose package_name # Verbose output
pip install --quiet package_name # Minimal output
pip install --progress-bar off package_name # Disable progress barInstall packages with cryptographic hash verification for security.
# Using requirements file with hashes
pip install --require-hashes -r requirements.txtRequirements file with hashes:
requests==2.28.1 \
--hash=sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97ddf \
--hash=sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349Control pip behavior through environment variables.
# Index configuration
export PIP_INDEX_URL=https://pypi.org/simple/
export PIP_EXTRA_INDEX_URL=https://test.pypi.org/simple/
export PIP_TRUSTED_HOST=pypi.org
# Installation options
export PIP_USER=1 # User installation
export PIP_NO_CACHE_DIR=1 # Disable cache
export PIP_REQUIRE_VIRTUALENV=1 # Require virtual environment
# Timeouts and retries
export PIP_TIMEOUT=60
export PIP_RETRIES=3
# Proxy configuration
export PIP_PROXY=http://user:password@proxy.server:portPip respects virtual environment activation and provides isolation.
# Using venv
python -m venv myenv
source myenv/bin/activate # On Windows: myenv\Scripts\activate
pip install package_name
# Using conda
conda create -n myenv python=3.9
conda activate myenv
pip install package_name
# Require virtual environment
pip install --require-virtualenv package_name
export PIP_REQUIRE_VIRTUALENV=1Use subprocess for programmatic package installation (recommended approach).
import subprocess
import sys
def install_package(package_name, upgrade=False, user=False):
"""Install a Python package using pip."""
cmd = [sys.executable, '-m', 'pip', 'install']
if upgrade:
cmd.append('--upgrade')
if user:
cmd.append('--user')
cmd.append(package_name)
try:
subprocess.check_call(cmd)
print(f"Successfully installed {package_name}")
except subprocess.CalledProcessError as e:
print(f"Failed to install {package_name}: {e}")
raise
def install_requirements(requirements_file):
"""Install packages from requirements file."""
cmd = [sys.executable, '-m', 'pip', 'install', '-r', requirements_file]
try:
subprocess.check_call(cmd)
print(f"Successfully installed from {requirements_file}")
except subprocess.CalledProcessError as e:
print(f"Failed to install from {requirements_file}: {e}")
raise
# Usage examples
install_package('requests')
install_package('django', upgrade=True)
install_requirements('requirements.txt')Install with Tessl CLI
npx tessl i tessl/pypi-pipevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10