
You can install packages one by one, or by setting a requirements.txt
file for your project.
pip install some-package
If you want to create a requirements.txt
file from the already installed packages, run the following command:
pip freeze > requirements.txt
The file will contain the list of all the packages installed in the current environment, and their respective versions. This will help you release your project with its own dependent modules.
Now that we have created a Python requirements file, it’s time to start adding some modules! The first step is to open the text document and add the names of the modules you would like to install.
For example, if I want to install the tensorflow
library into my project, I type in tensorflow
on its own line along with the required version. Let’s type an example in your newly created Python requirements.txt
file:
tensorflow==2.3.1
uvicorn==0.12.2
fastapi==0.63.0
Now that our Python requirements file is all set up, let’s take a look at how to install packages from it. To do this, we will use the pip package manager.
The pip
utility is used to install, upgrade, and uninstall Python packages. It is also used to manage Python virtual environments and more.
To start, open up a terminal or a command prompt and navigate to the directory of your Python project. Once you are there, type the following command:
pip install -r requirements.txt