A requirements file is a list of all of a project’s dependencies. This includes the dependencies needed by the dependencies. It also contains the specific version of each dependency, specified with a double equals sign (==
).
pip freeze
will list the current projects dependencies to stdout
.
This shell command will export this as a file named requirements.txt
:
$ pip freeze > requirements.txt
Once you’ve got your requirements file, you can head over to a different computer or new virtual environment and run the following:
$ pip install -r requirements.txt
That’s assuming you are working in the directory containing requirements.txt
. This tells pip
to install the specific versions of all the dependencies listed.
By modifying the requirements file to use >=
instead of ==
, you can tell pip
to install the latest stable version of the dependency, with the version specified acting as a minimum. This line would tell pip
to install the latest version of requests
, but never version 2.23.0: requests>=2.22.0, != 2.23.0
.
To upgrade your installed packages, run the following:
$ pip install --upgrade -r requirements.txt