`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?
As I said above, running pip freeze gives you a list of all currently installed dependencies, but that does mean all of them.
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.
Yup -- pip installs "bottom up" in the dependency tree -- installing the dependencies before dependent package, regardless of what is specified on the top level.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With