Python Project Dependencies
requirements.txt
Project dependencies are stored in a file named requirements.txt in the top level of the project, e.g.: [1]
django==1.6 bpython==0.12 django-braces==0.2.1 django-model-utils==1.1.0 logutils==0.3.3 South==0.7.6 requests==1.2.0 stripe==1.9.1 dj-database-url==0.2.1 django-oauth2-provider==0.2.4 djangorestframework==2.3.1
Anytime a package is installed with pip, it must be added to requirements.txt. Or better yet, add the package to requirements.txt and use the file to install the new package and verify the project's environment.
Also, make sure to create and load a virtual environment for the project before installing dependencies.
requirements.txt defines concrete dependencies for non-redistributable applications. It defines the dependencies between packages and the source for those packages, especially if they don't come from PyPi.
The dependencies in requirements.txt can be installed with:
$ pip install -r requirements.txt
setup.py
In addition to requirements.txt, setup.py is another file used to check for dependencies when installing a package. [2]
setup.py defines abstract dependencies for redistributable packages. The specific source for those dependencies should be defined elsewhere, e.g. requirements.txt.
Given a directiory containing a setup.py file, a requirements.txt file can be written that will install all dependencies found in setup.py from PyPi:
--index-url https://pypi.python.org/simple -e .
If any dependencies should come from another source, requirements.txt can be modified similar to this:
--index-url https://pypi.python.org/simple -e https://github.com/foo/bar.git#egg=bar -e .
pip will first install the bar library from GitHub, then move on to install all the dependencies found in setup.py. Since the bar library has already been installed at this point, it will be skipped over when installing libraries from PyPi.
Installing packages defined in setup.py
$ python setup.py install
Notes
See also
References
- ↑ Application Dependencies, Full Python Stack
- ↑ setup.py vs requirements.txt, Donald Stufft