Python
pip
package installation
programming
software development

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

bash
python -m pip install requests pandas numpy flask

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:

bash
python -m pip install "requests==2.32.3" "pandas>=2.2,<3.0" "numpy<2.0" "flask>=3.0"

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:

text
1requests==2.32.3
2pandas>=2.2,<3.0
3numpy<2.0
4flask>=3.0
5gunicorn==22.0.0
6sqlalchemy>=2.0
bash
python -m pip install -r requirements.txt

You can combine several requirements files with direct package names, which is common when production and development dependencies are kept separate:

bash
python -m pip install -r requirements.txt -r dev-requirements.txt pytest-cov

Generating requirements.txt from an existing environment

bash
1# Capture exact versions of everything installed
2python -m pip freeze > requirements.txt
3
4# Or use pip list for a human-readable view
5python -m pip list --format=columns

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.

bash
1# Create
2python -m venv .venv
3
4# Activate (Linux/Mac)
5source .venv/bin/activate
6
7# Activate (Windows Command Prompt)
8.venv\Scripts\activate
9
10# Activate (Windows PowerShell)
11.venv\Scripts\Activate.ps1
12
13# Install packages into the virtual environment
14python -m pip install -r requirements.txt

Once activated, python and pip point to the environment's copies, so every install is isolated. To leave it:

bash
deactivate

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."

bash
python -m pip install -r requirements.txt -c constraints.txt

requirements.txt:

text
flask>=3.0
celery>=5.3

constraints.txt:

text
werkzeug==3.0.4
kombu==5.3.7
redis==5.0.8

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

ApproachPinned VersionsLock FileSeparates Direct/TransitiveBuild Reproducibility
pip install pkg1 pkg2NoNoNoLow
requirements.txt (unpinned)PartialNoNoMedium
requirements.txt (fully pinned via freeze)YesEffectively yesNoHigh
pip-tools (pip-compile)YesYes (requirements.txt is the lock)Yes (requirements.in vs .txt)High
poetryYesYes (poetry.lock)Yes (pyproject.toml vs lock)High
pdm / uvYesYesYesHigh

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

bash
python -m pip install --upgrade requests pandas

Upgrade everything in a requirements file:

bash
python -m pip install --upgrade -r requirements.txt

See what is outdated first:

bash
python -m pip list --outdated

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

bash
1# Install from a Git repository
2python -m pip install "git+https://github.com/user/[email protected]"
3
4# Install from a local directory (editable mode for development)
5python -m pip install -e ./my-local-package
6
7# Install from a private index
8python -m pip install --index-url https://pypi.company.com/simple/ internal-package
9
10# Install from a wheel file
11python -m pip install ./dist/mypackage-1.0.0-py3-none-any.whl

These sources can be mixed in a requirements file:

text
requests==2.32.3
git+https://github.com/user/[email protected]
-e ./local-package

Verifying what got installed

bash
1# List all installed packages
2python -m pip list
3
4# Show details for a specific package
5python -m pip show requests
6
7# Check for dependency conflicts
8python -m pip check

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.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Data 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.

Practice algorithms