Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install numpy + pandas as dependency in setup.py

Installing numpy + pandas via setuptools as dependency in setup.py does not work for me. It is not about missing dependencies. If I install numpy via pip install numpy and afterwards python setup.py develop everything works fine. If I understand the setuptools documentation right, all packages are build first and then installed. So numpy is build, but not installed when pandas is build.

As a workaround I added numpy to my setup_requires. That works fine, but is obviously not a very clean solution.

Does anybody know a clean solution (Linux only is fine) for installing numpy + pandas via setuptools?

Update:

The dependency is configure via

install_requires=['numpy','pandas']

It does not make a difference, whether I add numpy explicitly or just add pandas. In both cases numpy will be downloaded and build, but pandas fails to build because some headers (which probably are installed during the install step of numpy, but not while building) cannot be found. If I install numpy first, everything works fine. I can reproduce this 100% and independent of the project I'm working on.

Update 2:

This is the end of the stack trace:

  File "/tmp/easy_install-QMa4ce/pandas-0.14.1/temp/easy_install-f6lreI/numpy-1.9.0/numpy/distutils/command/build_src.py", line 153, in run
  File "/tmp/easy_install-QMa4ce/pandas-0.14.1/temp/easy_install-f6lreI/numpy-1.9.0/numpy/distutils/command/build_src.py", line 170, in build_sources
  File "/tmp/easy_install-QMa4ce/pandas-0.14.1/temp/easy_install-f6lreI/numpy-1.9.0/numpy/distutils/command/build_src.py", line 329, in build_extension_sources
  File "/tmp/easy_install-QMa4ce/pandas-0.14.1/temp/easy_install-f6lreI/numpy-1.9.0/numpy/distutils/command/build_src.py", line 386, in generate_sources
  File "numpy/core/setup.py", line 432, in generate_config_h

  File "numpy/core/setup.py", line 42, in check_types
    entry_points={
  File "numpy/core/setup.py", line 293, in check_types

SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.

The message at the end is definitively wrong. If I do a pip install numpy before running python setup.py develop everything works fine. In the example above, I had only pandas in install_requires and no numpy. But as far as I could figure out, it makes no difference whether numpy is added explicitly or not.

like image 595
Achim Avatar asked Sep 09 '14 20:09

Achim


2 Answers

Please refer to the open issue https://github.com/numpy/numpy/issues/2434.

This is a known bug in numpy as it relates to setuptools.

As discussed there, use $ pip install -e . rather than $ python setup.py develop -- same result, but avoids this problem.

like image 79
Jason Avatar answered Oct 16 '22 02:10

Jason


These should be declared with the install_requires kwarg of setup. Here's an example project, geopandas, which requires pandas:

setup(name='geopandas',
      version=FULLVERSION,
      description='Geographic pandas extensions',
      license='BSD',
      author='Kelsey Jordahl',
      author_email='kjordahl@enthought.com',
      url='http://geopandas.org',
      long_description=LONG_DESCRIPTION,
      packages=['geopandas', 'geopandas.io', 'geopandas.tools'],
      install_requires=[
        'pandas', 'shapely', 'fiona', 'descartes', 'pyproj', 'rtree'],  # here
)

You can also specify versions required, see setuptools docs, as often you'll want to ensure the version is recent (has the features/bug-fixes you rely on) - here's how I do that in pep8radius.

like image 24
Andy Hayden Avatar answered Oct 16 '22 02:10

Andy Hayden