Python's standard library covers a lot, but almost every real project eventually needs something outside it — a web framework, an HTTP client, a data analysis library. pip is Python's official package installer, and it's how you pull third-party code from the Python Package Index (PyPI) straight into your project.
pip ships with Python automatically (from Python 3.4 onward), so if you've installed Python, you almost certainly already have it. You can confirm with:
pip --version
Output:
pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.12)
Installing a Package
pip install requests
That single command downloads the requests library (a very popular HTTP client) and makes it available to import in any Python script on your system — or, better, inside a specific virtual environment, which is the recommended way to keep each project's dependencies separate.
You can also install a specific version, which matters a lot once a project is in production and you don't want a library update silently changing behavior:
pip install requests==2.31.0
Checking What's Installed
pip list
pip show requests
pip list prints every package installed in the current environment with its version; pip show requests prints detailed info about one specific package, including where it's installed and what it depends on.
requirements.txt
Real projects don't make teammates install each dependency manually — they list every package the project needs in a file called requirements.txt:
requests==2.31.0
flask==3.0.2
python-dotenv==1.0.1
You can generate this file automatically from your current environment, and install everything from it on another machine, with:
pip freeze > requirements.txt
pip install -r requirements.txt
This is the standard way Python projects share their exact dependency list — pip freeze captures the precise installed versions, and -r requirements.txt reinstalls that exact set elsewhere (a fresh clone of the repo, a teammate's laptop, or a production server).
Upgrading and Uninstalling
pip install --upgrade requests
pip uninstall requests
One habit worth building early: always install packages inside a virtual environment rather than globally. Without one, pip installs packages system-wide, and it's very easy for two different projects on the same machine to end up silently requiring conflicting versions of the same library.
