342

I know it's an easy way of doing it but i didn't find it neither here nor on google. So i was curious if there is a way to install multiple packages using pip. Something like:

pip install progra1 , progra2 ,progra3 ,progra4 . 

or:

pip install (command to read some txt containing the name of the modules) 
Rafał Rawicki
  • 22,324
  • 5
  • 59
  • 79
Florin
  • 3,779
  • 5
  • 18
  • 15

9 Answers9

473

For installing multiple packages on the command line, just pass them as a space-delimited list, e.g.:

pip install wsgiref boto

For installing from a text file, then, from pip install --help:

-r FILENAME, --requirement=FILENAME

Install all the packages listed in the given requirements file. This option can be used multiple times.

Take a look at the pip documentation regarding requirements files for their general layout and syntax - note that you can generate one based on current environment / site-packages with pip freeze if you want a quick example - e.g. (based on having installed wsgiref and boto in a clean virtualenv):

$ pip freeze
boto==2.3.0
wsgiref==0.1.2
Community
  • 1
  • 1
Kristian Glass
  • 37,325
  • 7
  • 45
  • 73
  • 5
    "space-delimited list" does not seem to work for me if there are dependencies between the packages, eg: `sudo -H pip install setuptools trezor` causes this error: "Could not import setuptools which is required to install from a source distribution. Please install setuptools.". Instead, I need to run as 2 separate commands. – Jonathan Cross Nov 09 '17 at 14:15
  • Does this `pip install wsgiref boto` install the libraries with their dependencies as well? – mockash Feb 27 '20 at 09:23
145
pip install -r requirements.txt

and in the requirements.txt file you put your modules in a list, with one item per line.

  • Django=1.3.1

  • South>=0.7

  • django-debug-toolbar

Soviut
  • 88,194
  • 49
  • 192
  • 260
Radu Gheorghiu
  • 20,049
  • 16
  • 72
  • 107
  • How can I do the same using conda? any idea? conda intsall -r requirements.txt does not work. – CKM Aug 04 '17 at 05:10
  • Try this: https://stackoverflow.com/questions/35802939/install-only-available-packages-using-conda-install-yes-file-requirements-t – tisaconundrum Oct 31 '17 at 00:52
  • Do you have to specify the version #? In other words, if you just put `Django` on one line, would it automatically install the latest version? – Jon Grah Sep 15 '19 at 05:07
  • 3
    You don't have to specify a version number, and generally don't need to, though which version exactly `pip` then installs is sometimes hard to predict, especially if you have configured `pip` with multiple source indices and/or configuration options which constrain which packages can be installed. A common need is to specify a minimum version requirement, like `pip >= 9.0` – tripleee Sep 28 '19 at 12:29
  • You need a double == rather than one = – Jim Mar 24 '23 at 21:51
24

On the command line if you have a few packages to install, You may just do

pip install <package_1> <package_2>

Thanks,

Mike730
  • 495
  • 1
  • 5
  • 14
19

You can install packages listed in a text file called requirements file. For example, if you have a file called req.txt containing the following text:

Django==1.4
South==0.7.3

and you issue at the command line:

pip install -r req.txt

pip will install packages listed in the file at the specific revisions.

testworks
  • 386
  • 1
  • 10
Masci
  • 5,864
  • 1
  • 26
  • 21
  • Must I specify the version or can I just have `Django` on its own line and expect to get the latest version? Thanks. – PatrickT Feb 11 '22 at 18:25
14

You can use the following steps:

Step 1: Create a requirements.txt with list of packages to be installed. If you want to copy packages in a particular environment, do this

pip freeze >> requirements.txt

else store package names in a file named requirements.txt

Step 2: Execute pip command with this file

pip install -r requirements.txt
shreyaskar
  • 375
  • 1
  • 3
  • 14
6

Complementing the other answers, you can use the option --no-cache-dir to disable caching in pip. My virtual machine was crashing when installing many packages at once with pip install -r requirements.txt. What solved for me was:

pip install --no-cache-dir -r requirements.txt
victortv
  • 7,874
  • 2
  • 23
  • 27
1

You can simply place multiple name together separated by a white space like

C:\Users\Dell>pip install markdown django-filter

#c:\Users\Dell is path in my pc this can be anything on yours

this installed markdown and django-filter on my device. enter image description here

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
0

give the same command as you used to give while installing a single module only pass it via space delimited format

0

in the Jupyter kernel :

!py -3.11 -m pip install numpy pandas persiantools
M.Namjoo
  • 1
  • 1
  • There is an more modern user-friendly and consistent way inside Jupyter. In your example case, you'd run `%pip install numpy pandas persiantools`. See [here](https://stackoverflow.com/questions/28828917/error-importing-seaborn-module-in-python-importerror-cannot-import-name-utils/76347896#comment134631387_41925357) about the modern magic install commands for use inside cells in Jupyter notebooks that insure installation in the proper environment underlying the kernel. Please recommend current best practices. – Wayne Jul 27 '23 at 12:05
  • I think this is a very inefficient way to install multiple packages i.e. using a requirements file. An environment file to install using conda i.e .XML environment file – Nothing Jul 31 '23 at 19:58
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 31 '23 at 19:58