pip and Packages Beyond the Standard Library
The standard library is huge, but the true power of Python is PyPI — the Python Package Index — with over 500,000 free packages. One command installs almost any capability: web frameworks, AI libraries, PDF tools, you name it.
pip — your package manager
pip is Python’s installer (it ships with Python). The essential commands:
pip install package-name # install
pip install package-name==2.1.0 # install a SPECIFIC version
pip install --upgrade package-name # update
pip uninstall package-name # remove
pip list # what's installed
pip show package-name # details about one package
Install something real — the requests library (next lesson’s star):
pip install requests
Then import it like the standard library:
import requests
print(requests.__version__)
One command, one import — that’s the entire deal. This is why Python dominates: whatever you’re building, someone probably published the hard parts already.
Always inside a virtual environment
Module 2 taught venvs — this is where they matter most:
# the ritual for every new project
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install requests pandas
Without a venv, every package lands in one global pile — version conflicts between projects are inevitable. With a venv, each project owns its packages. Install globally = future chaos. Install in a venv = future calm.
requirements.txt — your project’s recipe
Freeze what you’ve installed so anyone (including future you, including deployment servers) can recreate the exact environment:
pip freeze > requirements.txt
The file looks like:
requests==2.31.0
streamlit==1.41.1
pandas==2.2.3
Recreating the environment anywhere:
pip install -r requirements.txt
This two-file pair (code + requirements.txt) is what makes projects portable — and it’s exactly what the Streamlit Cloud deployment in your other course requires.
Finding packages — how to choose
When you need a capability, search PyPI.org or ask: “python how to [task]”. With thousands of options, pick by:
- Downloads — PyPI shows monthly numbers; high = battle-tested
- Recent updates — abandoned packages rot as Python evolves
- Documentation — a package with good docs saves hours
The famous ones you’ll meet on your journey:
| Package | Superpower |
|---|---|
requests |
HTTP/API calls |
pandas |
data analysis |
streamlit |
web apps from Python |
numpy |
fast number crunching |
matplotlib |
charts |
beautifulsoup4 |
web scraping |
openai / mistralai |
AI APIs |
Common Errors & Fixes
pip: command not found— trypython -m pip install ...(runs pip through your Python, always works).- Installed but
ImportError— installed into a different Python than the one running. Check:which pythonandwhich pippoint to the same venv. Permission denied— installing globally without rights. The real fix: use a venv (neversudo pip).- Version conflicts — two projects need different versions of the same package. The entire reason venvs exist — separate them.
✅ Checkpoint
- Install requests version 2.31.0 exactly? (pip install requests==2.31.0)
- What file makes a project reproducible, and what creates it? (requirements.txt — pip freeze > requirements.txt)
- Why install inside a venv? (Per-project isolation — no version conflicts)
pip: command not found— what always works? (python -m pip install …)
Next: requests — your code’s passport to the internet.