Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip: install dependencies of dependencies

I would like to manually install all the requirements of a Python package I'm writing. To this end, I created the file requirements.txt and added the dependencies, line by line:

$ cat requirements.txt
meshio
numpy

When running

$ pip install -r requirements.txt

those two packages are installed alright, but I noticed that the dependencies of meshio aren't (i.e., whatever is listed in its requirements.txt). Not surprising, how is pip supposed to know?

Is there a mechanism for installing the entire dependency tree with pip?

like image 781
Nico Schlömer Avatar asked Dec 08 '22 22:12

Nico Schlömer


2 Answers

Turns out for the dependencies to be installed, the packages needs to list its dependencies as

install_requires=[
    'numpy',
    'pyyaml'
],

as part of setup() in setup.py, not in requirements.txt.

like image 62
Nico Schlömer Avatar answered Dec 10 '22 12:12

Nico Schlömer


You may be interested by pip-tools, a python package that can be used to build a requirements.txt file that takes into account all underlying dependencies. It can be installed via pip:

pip install --upgrade pip  # pip-tools needs pip>=6.
pip install pip-tools

Once installed, you can use the pip-compile command to generate your requirements file. For example, suppose you work on a Flask project. You would have to do the following:

Write the following line to a file:

Flask

Run pip-compile <your-file>. It will produce your requirements.txt, with all the dependencies pinned. You can re-run pip-compile to update the packages. Your output file will look like this:

#
# This file is autogenerated by pip-compile
# Make changes in requirements.in, then run this to update:
#
#    pip-compile <your-file>
#
flask==0.10.1
itsdangerous==0.24        # via flask
jinja2==2.7.3             # via flask
markupsafe==0.23          # via jinja2
werkzeug==0.10.4          # via flask
like image 23
Knak Avatar answered Dec 10 '22 10:12

Knak