Home Knowledge Base pip

pip is Python's standard package installer and dependency manager, the essential tool for installing, upgrading, and managing Python libraries and dependencies from PyPI (Python Package Index).

What Is pip?

Why pip Matters

Basic Commands

Installation:

# Install latest version
pip install requests

# Install specific version
pip install requests==2.28.0

# Install version range
pip install requests>=2.28.0,<3.0.0

# Install from requirements file
pip install -r requirements.txt

Upgrades & Removal:

# Upgrade to latest
pip install --upgrade requests

# Uninstall package
pip uninstall requests

# Uninstall multiple
pip uninstall requests flask django -y

Information & Search:

# List installed packages
pip list

# Show package details
pip show requests

# Check for outdated packages
pip list --outdated

# Search PyPI
pip search "web scraping"

Requirements Files

Create requirements.txt (capture current environment):

pip freeze > requirements.txt

Install from requirements:

pip install -r requirements.txt

Example requirements.txt:

requests==2.28.0              # Exact version
flask>=2.0.0                  # Minimum version
pandas~=1.5.0                 # Compatible version (1.5.x)
numpy                         # Latest version

Version Specifiers:

SpecifierMeaning
==Exact version
>=Minimum version
<=Maximum version
>Greater than
<Less than
~=Compatible version

Virtual Environments

Why Virtual Environments?

Create Virtual Environment:

# Create venv
python -m venv myenv

# Activate (Linux/Mac)
source myenv/bin/activate

# Activate (Windows)
myenvScriptsactivate

# Check it's active
which python      # Should show myenv path

# Deactivate
deactivate

Usage Pattern:

# Create for project
cd myproject
python -m venv venv

# Activate
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Develop
python app.py

# Deactivate when done
deactivate

Advanced pip Usage

Install from GitHub:

pip install git+https://github.com/user/repo.git

# Specific branch
pip install git+https://github.com/user/repo.git@branch-name

# From URL
pip install https://github.com/user/repo/archive/main.zip

Editable Install (Development mode):

# Install package in development mode
pip install -e .

# Changes to code immediately reflected
# Perfect for developing packages

Install with Extras:

# Package can define optional dependencies
pip install requests[security]     # With SSL extras
pip install requests[socks]        # With socks support
pip install requests[security,socks]

Upgrade pip Itself:

# macOS/Linux
pip install --upgrade pip

# Windows
python -m pip install --upgrade pip

Generate Requirements with Specific Packages:

# Only packages you directly installed
pip install pipreqs
pipreqs /path/to/project

Common Issues & Solutions

IssueSolution
Permission deniedUse pip install --user or virtualenv
Module not foundActivate correct virtualenv
Version conflictsUse virtualenv to isolate
Broken installpip install --force-reinstall
Outdated pipRun pip install --upgrade pip

Alternatives to pip

conda:

# Manages Python + packages + dependencies
conda install numpy pandas scikit-learn

poetry:

# Modern Python packaging
poetry add requests
poetry install

pipenv:

# Combines pip + virtualenv
pipenv install requests
pipenv run python app.py

uv (Emerging):

# Ultra-fast pip replacement
uv pip install requests

Best Practices

1. Always use virtualenv: Isolate projects 2. Commit requirements.txt: Share dependencies 3. Specify versions: Avoid surprises in production 4. Keep pip updated: pip install --upgrade pip 5. Review before install: pip install --dry-run (some versions) 6. Use hash checking: Security in production

pip install --require-hashes -r requirements.txt

7. Pin transitive dependencies: Lock all nested deps

pip freeze > requirements-lock.txt

Real-World Workflow

# New project
mkdir myproject && cd myproject

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install flask requests sqlalchemy

# Save for reproducibility
pip freeze > requirements.txt

# Later: Developer clones repo
git clone myproject
cd myproject
python -m venv venv
source venv/bin/activate

# Install exact same versions
pip install -r requirements.txt

# Ready to develop!

pip is the backbone of Python development — without it, Python would lack the accessibility that makes it valuable for beginners and powerful for professionals.

pipinstallpackage

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.