[Numpy-discussion] specifying numpy as dependency in your project, install_requires

Frédéric Bastien nouiz@nouiz....
Fri Sep 21 15:45:25 CDT 2012


On Fri, Sep 21, 2012 at 4:37 PM, Benjamin Root <ben.root@ou.edu> wrote:
>
>
> On Fri, Sep 21, 2012 at 4:19 PM, Travis Oliphant <travis@continuum.io>
> wrote:
>>
>>
>> On Sep 21, 2012, at 3:13 PM, Ralf Gommers wrote:
>>
>> Hi,
>>
>> An issue I keep running into is that packages use:
>>     install_requires = ["numpy"]
>> or
>>     install_requires = ['numpy >= 1.6']
>>
>> in their setup.py. This simply doesn't work a lot of the time. I actually
>> filed a bug against patsy for that
>> (https://github.com/pydata/patsy/issues/5), but Nathaniel is right that it
>> would be better to bring it up on this list.
>>
>> The problem is that if you use pip, it doesn't detect numpy (may work
>> better if you had installed numpy with setuptools) and tries to
>> automatically install or upgrade numpy. That won't work if users don't have
>> the right compiler. Just as bad would be that it does work, and the user
>> didn't want to upgrade for whatever reason.
>>
>> This isn't just my problem; at Wes' pandas tutorial at EuroScipy I saw
>> other people have the exact same problem. My recommendation would be to not
>> use install_requires for numpy, but simply do something like this in
>> setup.py:
>>
>>     try:
>>         import numpy
>>     except ImportError:
>>         raise ImportError("my_package requires numpy")
>>
>> or
>>
>>     try:
>>         from numpy.version import short_version as npversion
>>     except ImportError:
>>         raise ImportError("my_package requires numpy")
>>     if npversion < '1.6':
>>        raise ImportError("Numpy version is %s; required is version >= 1.6"
>> % npversion)
>>
>> Any objections, better ideas? Is there a good place to put it in the numpy
>> docs somewhere?
>>
>>
>> I agree.   I would recommend against using install requires.
>>
>> -Travis
>>
>>
>
> Why?  I have personally never had an issue with this.  The only way I could
> imagine that this wouldn't work is if numpy was installed via some other
> means and there wasn't an entry in the easy-install.pth (or whatever
> equivalent pip uses).  If pip is having a problem detecting numpy, then that
> is a bug that needs fixing somewhere.
>
> As for packages getting updated unintentionally, easy_install and pip both
> require an argument to upgrade any existing packages (I think -U), so I am
> not sure how you are running into such a situation.

If a user use that option, it will also try to updaet NumPy. This is a
bad default behavior. The work aroud is to pass -U and --no-deps to
don't update the dependency. People don't want to update numpy when
they update there package other package as Theano.

> I have found install_requires to be a powerful feature in my setup.py
> scripts, and I have seen no reason to discourage it.  Perhaps I am the only
> one?

What about if numpy is installed and recent enough, don't put in in
the install_require. If not there, add it there?
It will still fail if not c compiler is there, but maybe it won't
update it at then same time?

Fred


More information about the NumPy-Discussion mailing list