How can I install packages using pip according to the requirements.txt file from a local directory?

To install packages using pip from a local directory, you can use the -r option to specify the path to the requirements.txt file. For example, if the requirements.txt file is in the same directory as your Python script, you can use the following command:

pip install -r requirements.txt

Watch a course Python - The Practical Guide

Alternatively, you can specify the path to the requirements.txt file if it is located in a different directory. For example:

pip install -r /path/to/requirements.txt

This will install all of the packages listed in the requirements.txt file.

You can also use the --upgrade option to upgrade the packages to the latest version if they are already installed:

pip install --upgrade -r requirements.txt