How to install multiple Python packages at once with pip
Codemia Knowledge Hub ·
List the package names after pip install to install them all in one command. For repeatable setups, put the packages in a requirements.txt file and run pip install -r requirements.txt. Install into a virtual environment rather than the system Python to avoid dependency conflicts between projects.
Listing packages on the command line
pip resolves all dependencies together and installs everything in one pass. python -m pip instead of bare pip guarantees you install into the intended interpreter, which matters when several Python versions are installed.
You can pin or constrain versions inline. The quotes stop the shell from treating > and < as redirections:
Installing from a requirements file
For anything beyond a quick script, requirements.txt is the standard way to declare dependencies, one per line with optional version constraints:
You can combine several requirements files with direct package names, which is common when production and development dependencies are kept separate:
Generating requirements.txt from an existing environment
pip freeze outputs pinned versions (for example requests==2.32.3), which makes builds reproducible. It also includes every transitive dependency. For a file that lists only your direct dependencies, maintain requirements.txt by hand or use pip-compile from pip-tools.
Using a virtual environment
Installing into the system Python is risky: projects may need different versions of the same library, and system-level installs can conflict with packages managed by the OS package manager.
Once activated, python and pip point to the environment's copies, so every install is isolated. To leave it:
Requirements vs constraints files
A requirements file says "install these packages." A constraints file says "if these packages get installed, directly or as dependencies, use these versions."
requirements.txt:
constraints.txt:
This pins transitive dependencies without listing them as direct requirements, giving you control of the full tree while keeping the requirements file focused.
Comparing dependency management approaches
| Approach | Pinned Versions | Lock File | Separates Direct/Transitive | Build Reproducibility |
pip install pkg1 pkg2 | No | No | No | Low |
requirements.txt (unpinned) | Partial | No | No | Medium |
requirements.txt (fully pinned via freeze) | Yes | Effectively yes | No | High |
pip-tools (pip-compile) | Yes | Yes (requirements.txt is the lock) | Yes (requirements.in vs .txt) | High |
poetry | Yes | Yes (poetry.lock) | Yes (pyproject.toml vs lock) | High |
pdm / uv | Yes | Yes | Yes | High |
For production applications, pip-tools or poetry are better than raw pip freeze because they separate what you asked for from what was pulled in transitively.
Upgrading several packages
Upgrade everything in a requirements file:
See what is outdated first:
Be careful with broad upgrades in mature projects, since a new major version can break things. Upgrade one package at a time and run tests after each change.
Installing from Git, local paths and private indexes
These sources can be mixed in a requirements file:
Verifying what got installed
pip check reports packages whose declared dependencies are not satisfied (for example, package A requires requests>=2.30 but requests 2.28 is installed). Run it after every install to catch conflicts early.
Mistakes that cause broken installs
Using bare pip with multiple Pythons installed. pip might point to Python 2 or a different Python 3. python -m pip ties the install to a specific interpreter.
Installing globally with sudo pip install. This modifies system-managed packages and can break OS tools. On Debian/Ubuntu it is now blocked by default (PEP 668). Use a virtual environment.
Treating requirements.txt as a lock file. Ranges like requests>=2.30 can resolve to a different version on every install. For reproducible builds, pin exact versions with pip freeze or use pip-tools.
Mixing pinned and unpinned packages. flask==3.0.0 with werkzeug>=3.0 can break when a new werkzeug release is incompatible with the pinned flask. Pin everything or use constraints for transitive versions.
Forgetting to activate the virtual environment. If which python shows /usr/bin/python instead of .venv/bin/python, you are installing globally.
Skipping pip check. A package may import fine and then crash at runtime when it calls a function missing from the installed version of a dependency.
Related reading
- How to install PIL with pip on Mac OS?
- How to install pip with Python 3?
- how to install pip with yum on EC2
- How to install psycopg2 with pip on Python?
- How to install python3 version of package via pip on Ubuntu?
- How to install Python 3.8 along with Python 3.9 in Arch Linux?
- How to install python modules without root access?
- How to install Python MySQLdb module using pip?
System design interview problems on this topic
- Design a Web Crawler: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a URL Shortener (TinyURL): solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.