Python pip and Dependency Management Basics
SkillVeris Team
Engineering Team

pip is Python's package installer; it downloads libraries from PyPI and manages their versions inside your environment.
In this guide, you'll learn:
- Always install packages into a virtual environment so each project keeps its own isolated set of dependencies.
- A requirements.txt file records exact package versions so anyone can recreate your environment with one command.
- Version pinning with == guarantees reproducible installs; version ranges trade reproducibility for easier updates.
- pip freeze captures the current environment, while pip list shows what is installed in a readable table.
1What Is pip?
pip is Python's official package installer. It downloads libraries from the Python Package Index (PyPI), installs them into your environment, and tracks their versions so your code has the tools it depends on. When you run pip install requests, pip fetches the package and everything it needs to work.
Dependency management is the practice of controlling which packages, and which versions of them, your project uses. Done well, it means your code runs the same on your laptop, a teammate's machine, and a production server. Done poorly, it produces the classic 'works on my machine' problem.
2Basic pip Commands
A small set of commands covers almost everything you will do day to day with pip. Each runs from your terminal inside an activated environment.
- pip install requests # install the latest version
- pip install requests==2.31.0 # install an exact version
- pip install --upgrade requests # upgrade to the newest release
- pip uninstall requests # remove a package
- pip list # show installed packages
- pip show requests # show details about one package
💡Pro Tip
Run python -m pip install instead of a bare pip if you juggle multiple Python versions. It guarantees the pip you use belongs to the interpreter you expect.
3Why Virtual Environments Matter
A virtual environment is an isolated folder that holds a project's own Python interpreter and packages. Without one, every pip install lands in a single global location, so two projects that need different versions of the same library will conflict. Virtual environments give each project a clean, private space.
Creating and Activating One
Python ships with the venv module, so no extra install is needed. Create an environment, activate it, and every pip command afterward affects only that project.
python -m venv .venv # create the environment
source .venv/bin/activate # activate on macOS or Linux
.venv\Scripts\activate # activate on Windows
deactivate # leave the environment4Using requirements.txt
A requirements.txt file lists your project's dependencies so anyone can install them all at once. Generate it from a working environment with pip freeze, then commit it to version control. A new contributor recreates your exact setup with a single install command.
- pip freeze > requirements.txt # capture current versions
- pip install -r requirements.txt # install everything listed
- requests==2.31.0 # a pinned line inside the file
- flask>=3.0 # allow 3.0 or newer
- numpy # any version (not recommended for production)
5Version Pinning and Specifiers
Version specifiers tell pip which releases are acceptable. Pinning with == locks an exact version for maximum reproducibility, while ranges like >= or the compatible-release operator ~= allow controlled updates. The right choice depends on whether you value stability or fresh features more for a given dependency.
- requests==2.31.0 # only this exact version
- requests>=2.28,<3.0 # a range that excludes major bumps
- requests~=2.31.0 # compatible releases: 2.31.x but not 2.32
- requests # unpinned, whatever is newest today
⚠️Watch Out
Unpinned dependencies are a common cause of surprise breakage. A dependency you never touched can release a new version that changes behavior and silently breaks your build.
6Beyond Plain pip
Plain pip does not lock the full dependency tree, so newer tools add that layer. pip-tools compiles a loose requirements.in into a fully pinned requirements.txt. Poetry manages dependencies, virtual environments, and packaging together. uv is a fast, drop-in resolver written in Rust. All build on the same PyPI ecosystem, so learning pip first makes each easier to adopt.
- pip-tools: compile pinned lock files from high-level inputs.
- Poetry: all-in-one dependency, environment, and build management.
- uv: a very fast installer and resolver compatible with pip workflows.
- conda: popular in data science for handling non-Python dependencies too.
7Best Practices for Dependency Management
A few consistent habits prevent the majority of dependency headaches over a project's life.
- Always work inside a virtual environment, one per project.
- Commit your requirements file or lock file so environments are reproducible.
- Pin exact versions for production; use ranges only when you actively want updates.
- Separate development-only tools (linters, test runners) into a second requirements file.
- Review dependency updates before applying them rather than upgrading blindly.
- Keep the number of direct dependencies small; every package is code you now trust.
8Key Takeaways
Solid dependency management is what makes Python projects portable and reliable.
- pip installs and manages packages from PyPI.
- Virtual environments isolate each project's dependencies.
- requirements.txt makes an environment reproducible for anyone.
- Pin versions for stability; use ranges deliberately for updates.
- Tools like Poetry and uv extend pip with proper lock files.
9Frequently Asked Questions
Q: What is the difference between pip and a virtual environment? A: pip is the tool that installs packages, while a virtual environment is the isolated location those packages install into. You use pip inside a virtual environment so each project keeps its own dependencies.
Q: How do I recreate someone else's Python environment? A: Activate a fresh virtual environment and run pip install -r requirements.txt using the requirements file they committed. pip installs every listed package at the recorded versions.
Q: Should I pin exact versions or use ranges? A: Pin exact versions with == for production so builds are reproducible. Use ranges when you want a library to update automatically and you are confident its changes will stay compatible.
Q: Do I need Poetry or uv, or is pip enough? A: pip alone is enough for many projects. Reach for Poetry or uv when you want reliable lock files, faster installs, or combined environment and packaging management.
Get The Print Version
Download a PDF of this article for offline reading.
About the Publisher
SkillVeris Team
Engineering Team
Our engineering writers turn abstract code concepts into hands-on, project-driven learning experiences.
View all postsRelated Posts
Never miss an update
Get the latest tutorials and guides delivered to your inbox.
No spam. Unsubscribe anytime.