Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip freeze and order of dependencies

Tags:

python

pip

`pip freeze > requirements.txt` 

automatically writes my dependencies in an apparently alphabetically order, like this:-

matplotlib==1.2.0
numpy==1.6.2
pandas==0.9.1

The problem with this is that pip install -r requirements.txt (when I deploy my code with its dependencies listed in requirements.txt) will end up failing because matplotlib needs numpy to be installed first.

How can I ensure that matplotlib is listed after numpy in the requirements.txt file when I pip freeze it?

like image 514
Calvin Cheng Avatar asked Apr 09 '13 02:04

Calvin Cheng


People also ask

Does pip freeze show dependencies?

As I said above, running pip freeze gives you a list of all currently installed dependencies, but that does mean all of them.

Why you shouldn't use pip freeze?

pip freeze might seem very useful initially but it can mess up your project because of the following reasons: It dumps all the libraries installed in your project including dependencies and sub-dependencies in the requirements. txt file. It still misses out on the libraries that are not installed using pip.

Does pip install requirements in order?

Yup -- pip installs "bottom up" in the dependency tree -- installing the dependencies before dependent package, regardless of what is specified on the top level.

How do I freeze requirements for pip?

The recommended approach is to use a requirements. txt file (readthedocs.org) that contains a list of commands for pip that installs the required versions of dependent packages. The most common command is pip freeze > requirements. txt , which records an environment's current package list into requirements.


2 Answers

For your case it does not matter, because pip builds every requirements (calling python setup.py egg_info for each) and then install them all. For your specific case, it does not matter, because numpy is currently required to be installed while building matplotlib.

It is a problem with matplotlib, and they created a proposal to fix it: https://github.com/matplotlib/matplotlib/wiki/MEP11

See comments from this issue at pip issue tracker: https://github.com/pypa/pip/issues/25

This question is a duplicate of Matplotlib requirements with pip install in virtualenv.

like image 101
Hugo Tavares Avatar answered Oct 11 '22 21:10

Hugo Tavares


You can try command

pip install --no-deps -r requirements.txt

This installs the packages without dependencies and possibly you will get rid above written problems.

like image 38
Vladimir Chub Avatar answered Oct 11 '22 23:10

Vladimir Chub