This article will discuss two different ways to install multiple python packages in a single command using pip. These two ways are,
- Using the raw pip install command.
- Using requirements.txt with the pip install command
Let’s discuss them one by one,
Install multiple python packages in a single pip install command
We can pass the space-delimited list of package names to the pip install command. For example,
pip install pandas numpy flask pytz
It will install three packages i.e.
- pandas
- numpy
- flask
- pytz
To confirm that all the given packages have been installed or not, we can run this command to check all the installed packages i.e.
pip freeze
Output:
click==8.0.3 Flask==2.0.2 itsdangerous==2.0.1 Jinja2==3.0.2 MarkupSafe==2.0.1 numpy==1.21.2 pandas==1.3.3 python-dateutil==2.8.2 pytz==2021.3 six==1.16.0 Werkzeug==2.0.2
To install specific versions of multiple python packages in a single command, you can specify the version number along with package names in space separated list. For example,
Frequently Asked:
- How to subtract days from a date in Python?
- Python: Pretty print nested dictionaries – dict of dicts
- How to convert a string to a boolean in Python?
- Replace all occurrences of a substring in string – Python
pip install pandas==1.3.2 numpy==1.21.2 Flask==2.0.2
It will install all the specified versions of all the given python packages.
Install multiple python packages at once using requirements.txt
If you have an extensive list of packages to install, it is better to put them in a file named reqiurements.txt and install them in a single pip command. But command will be relatively shorter in this case. Let’s understand by an example,
Suppose you want to install four python packages, i.e., pandas, numpy, pytz, and flask. Then create requirements.txt with is content i.e.
Flask==2.0.2 numpy==1.21.2 pandas==1.3.2 pytz==2021.3
We have specified the version of packages too. The version number is optional, and if not provided, it will install the latest version of the package by default.
Now run the pip install command to install all the packages in requirements.txt i.e.
pip install -r requirements.txt
It will install all the packages specified in the requirements.txt
Summary
We learned two different ways to install multiple python packages in a single command.