Courses/Python Mastery/Module 11: The Python Ecosystem
Module 11 · Lesson 120 minBeginner

pip and Packages Beyond the Standard Library

Lesson goal
Install, upgrade, and manage third-party packages without fear.

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:

code
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):

code
pip install requests

Then import it like the standard library:

code
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:

code
# 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:

code
pip freeze > requirements.txt

The file looks like:

code
requests==2.31.0
streamlit==1.41.1
pandas==2.2.3

Recreating the environment anywhere:

code
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:

    PackageSuperpower
    requestsHTTP/API calls
    pandasdata analysis
    streamlitweb apps from Python
    numpyfast number crunching
    matplotlibcharts
    beautifulsoup4web scraping
    openai / mistralaiAI APIs

    Common Errors & Fixes

  • `pip: command not found` — try python -m pip install ... (runs pip through your Python, always works).
  • Installed but `ImportError` — installed into a different Python than the one running. Check: which python and which pip point to the same venv.
  • `Permission denied` — installing globally without rights. The real fix: use a venv (never sudo 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.