DEV Community

Waylon Walker
Waylon Walker

Posted on • Originally published at waylonwalker.com

4 1

Nested requirements.txt in python

python requirements text files can in fact depend on each other due to the fact that you can pass pip install arguments right into your
requirements.txt file. The trick is to just prefix the file with a
-r flag, just like you would if you were installing it with pip
install

try it out

Lets create two requirements files in a new directory to play with.

mkdir requirements-nest cd requirements-nest touch requirements.txt requirements_dev.txt
Enter fullscreen mode Exit fullscreen mode

Then add the following to each requirements file.

# requirements.txt
kedro[pandas.ParquetDataSet]
Enter fullscreen mode Exit fullscreen mode
# requirements_dev.txt
-r requirements.txt
ipython
Enter fullscreen mode Exit fullscreen mode

Installing

Installing requirements_dev.txt will install both ipython and pandas since it includes the base requirements file.

# this will install only pandas
pip install -r requirements.txt

# this will install both ipython and pandas
pip install -r requirements_dev.txt
Enter fullscreen mode Exit fullscreen mode

Links

This is covered in the pip user guide, but it is not obvious that this can be done in a requirements.txt file.

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

Neon image

Set up a Neon project in seconds and connect from a Python application

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay