msampaio
msampaio

Reputation: 3433

Matplotlib requirements with pip install in virtualenv

I have a requirements.txt file like this:

numpy
matplotlib

When I try pip install -r requirements.txt inside a new virtualvenv, I get this:

REQUIRED DEPENDENCIES

             numpy: no

                    * You must install numpy 1.1 or later to build

                    * matplotlib.

If I install numpy first and matplotlib after, it works. However I'd like to keep using pip install -r requirements.txt. Is it possible?

Upvotes: 23

Views: 14613

Answers (6)

bmu
bmu

Reputation: 36184

Matplotlib and pip don't seem to play together very well. So I don't think it is possible in this case.

pip first downloads a package listed in your requirements file and than runs setup.py, but it doesn't really install it (I'm not quite sure about the internals of pip). After all packages are prepared in this way, they are installed.

The problem is, that matplotlib checks if numpy is installed in its setup.py (the check itself is defined in setupext.py). So at the moment the check is performed, numpy is not installed and the matplotlib setup.py exits with the error message you received (This may not be a bug, as it may require numpy to build).

This was once addressed in pip issue #24 and issue #25. The issues are closed but give some more details.

What I am doing up to now is to first install numpy and than install all packages from my requirements file.

Update 12/2012

There is a new open pip issue which deals with this problem.

Update 04/2013

The issue is closed as WONTFIX

Upvotes: 22

Sergey Orshanskiy
Sergey Orshanskiy

Reputation: 7054

I made it work in virtualenv inside an iPython notebook!

I have

ipython==2.2.0
numpy==1.8.2
matplotlib==1.4.2

It works in an iPython notebook with

%matplotlib inline
from pylab import *
plot([1,2,3])

It does not work in an iPython console, though, but I am perfectly happy to do my graphing in the notebook!

At one point I was able to trick it into working from the console by installing some thing in the virtualenv, but other things only in the global namespace, but I forgot how I did it. I just kept installing and uninstalling things.

Upvotes: 0

jasterm007
jasterm007

Reputation: 173

I've just gotten used to invoking a script to repeatably set up my virtualenv; it involves two requirements file: one with only numpy, and a second one with everything else.

It's not a terrible thing to get used to, since pip will try to do 'all or nothing' when you install via a requirements file. This way, you can stage the installation so dependencies are installed first.

Upvotes: 0

barracel
barracel

Reputation: 1829

It's a known problem of the library and it's currently being discussed as a Matplotlib enhancement proposal: https://github.com/matplotlib/matplotlib/wiki/MEP11. Until it's fixed the only solution I can imagine is repackaging the library to remove the numpy check.

Upvotes: 10

mechmind
mechmind

Reputation: 1767

After playing with pip lately i realized that requirements file should be rearranged manually, preferably while generating it.

In simple case (i.e. just numpy and matplotlib requires ordering), you can just reverse requrements file: pip freeze | sort -r

Upvotes: 0

Sevak Avakians
Sevak Avakians

Reputation: 938

Yes. "requirements.txt" is just a flat file from which pip can use to install packages. In that file, you can change the version of the dependencies. For example, it looks like you need at least 1.1, so try changing the line with 'numpy' to be:

numpy==1.1

Or, you can use >= like this:

numpy>=1.1

This may be what's holding you up. But, AFAIK, matplotlib should have a dependency on numpy already. Seems like that may need to be fixed.

See also this How to pip install a package with min and max version range?

and

In setup.py or pip requirements file, how to control order of installing package dependencies?

Upvotes: 1

Related Questions