Skip to content
Advertisement

Dependencies of Django Project

I created a setup.py and setup.cfg like explained in the Django docs.

Now I am unsure how to add dependencies to my project.

If someone installs my code, other tools like Pillow should automatically get installed.

I read that install_requires is the right way (not requirements.txt), but how to specify this?

The file setup.py looks pretty generic, and all content is in setup.cfg.

But examples I see all have their list of dependencies in setup.py via install_requires.

How to specify the dependencies of a Django project?

Advertisement

Answer

It’s a bit odd that the Django docs on this are lacking. But yes, install_requires argument to setup() or install_requires key in setup.cfg are the way to go.

You should depend on Django and if you’re relying on Pillow, pillow as well.

You can still use requirements.txt and if you want to be future friendly (as setup.py is on its way out – but that will take a long time), it’s recommended to do so.

Putting that all together, I would add:

requirements.txt

Django==maj.min.patch
Pillow==maj.min.patch

setup.py

#!/usr/bin/env python
from setuptools import setup
import os.path


def read_requirements():
    path = os.path.join(os.path.dirname(__file__), "requirements.txt")
    with open(path, "rt") as f:
        requirements = f.read()

    return requirements.splitlines(keepends=False)


setup(install_requires=read_requirements())
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement