pip is the official package installer for Python, allowing developers to install, upgrade, inspect, and remove third-party packages hosted on the Python Package Index (PyPI).
flowchart TD
A["PyPI Repository (pypi.org)"] -->|pip install| B["Virtual Environment (.venv/site-packages)"]
B -->|pip freeze| C["requirements.txt"]
C -->|pip install -r| D["Reproducible Deployment Environment"]
pip Commands# Install package
pip install requests
# Install specific version
pip install fastapi==0.110.0
# Export installed dependencies
pip freeze > requirements.txt
# Install from requirements file
pip install -r requirements.txt
# Uninstall package
pip uninstall requests -y
import pkg_resources
import sys
from typing import List, Dict
def inspect_installed_packages(target_packages: List[str]) -> Dict[str, str]:
"""Check installed versions of target packages in active environment."""
results = {}
for pkg in target_packages:
try:
version = pkg_resources.get_distribution(pkg).version
results[pkg] = version
except pkg_resources.DistributionNotFound:
results[pkg] = "Not Installed"
return results
if __name__ == "__main__":
check_list = ["urllib3", "pip", "setuptools", "non_existent_pkg"]
pkg_status = inspect_installed_packages(check_list)
print("--- Package Distribution Status ---")
for name, ver in pkg_status.items():
print(f" {name:<20}: {ver}")
venv: Installing packages without an active virtual environment pollutes the global operating system Python.requirements.txt, pin exact versions (package==1.2.3) to prevent unexpected breaking changes on deployment.uv or poetry for ultra-fast dependency resolution and lockfile management.Create a virtual environment, run pip install requests, generate a requirements.txt using pip freeze, and inspect its content.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With