SyntaxStudy
Sign Up
Python Beginner 8 min read

pip & Package Management

pip & Package Management

pip is Python's package installer. It downloads packages from PyPI (the Python Package Index) and installs them into your environment.

Basic pip Commands

# Install a package
pip install requests

# Install specific version
pip install "requests==2.31.0"

# Install minimum version
pip install "requests>=2.28"

# Uninstall
pip uninstall requests

# Upgrade
pip install --upgrade requests

Listing & Searching

# List installed packages
pip list
pip list --outdated

# Show package info
pip show requests

# Search (deprecated, use pypi.org)
pip search requests

requirements.txt

# Generate
pip freeze > requirements.txt

# Install from file
pip install -r requirements.txt

# requirements.txt example:
requests==2.31.0
flask>=3.0.0
numpy>=1.24,<2.0
pytest

pip in Python Scripts

import subprocess, sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "requests"])

Useful Packages by Category

"""
Web:     flask, fastapi, django, requests, httpx
Data:    pandas, numpy, polars, scipy
ML:      scikit-learn, tensorflow, torch, transformers
CLI:     click, typer, rich, argparse
Testing: pytest, hypothesis, coverage
"""
Example
import sys

# Show pip version and location
print("Python:", sys.version)
print("Executable:", sys.executable)
print()

# List installed packages programmatically
import importlib.metadata as meta
pkgs = sorted(meta.packages_distributions().keys())
print(f"Installed packages ({len(pkgs)} found):")
for pkg in pkgs[:10]:
    print(f"  {pkg}")
print("...")
Pro Tip

Never run pip install as root/admin system-wide. Always use a virtual environment so project dependencies do not conflict with each other.