在setup.py中安装numpy + pandas依赖项。

9
安装numpy+pandas作为setup.py依赖项时,使用setuptools并不起作用。这与缺少依赖项无关。如果我通过pip install numpy安装numpy,然后再运行python setup.py develop,一切都正常。如果我正确理解了setuptools文档,所有包都会先构建,然后再安装。因此numpy被构建了,但在构建pandas时没有被安装。
作为解决方法,我将numpy添加到了我的setup_requires中。这可以正常工作,但显然不是一个非常干净的解决方案。
有没有人知道一个干净的解决方案(仅限Linux)来通过setuptools安装numpy+pandas
更新:
依赖关系是通过设置完成的。
install_requires=['numpy','pandas']

无论是显式添加numpy还是只添加pandas,都不会有任何区别。在这两种情况下,numpy都将被下载和构建,但是pandas构建失败,因为找不到一些头文件(这些头文件可能在安装numpy的安装步骤中安装,但在构建时未安装)。如果我先安装numpy,则一切正常。我可以100%地重现这个问题,而且与我正在工作的项目无关。
更新2:
以下是堆栈跟踪的结尾:
  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.

结尾的信息肯定是错误的。如果在运行 python setup.py develop 之前执行 pip install numpy,一切都可以正常工作。在上面的示例中,我只在 install_requires 中有 pandas,没有 numpy。但据我所知,无论是否明确添加 numpy,都没有任何区别。

你目前是如何声明它作为依赖项的?(那种方式不起作用。) - Andy Hayden
2个回答

7
请参考开放问题https://github.com/numpy/numpy/issues/2434
这是numpy中与setuptools相关的已知错误。
如在讨论中所述,请使用$ pip install -e .而不是$ python setup.py develop——结果相同,但避免了此问题。

2

这些应该在setup的install_requires参数中声明。下面是需要pandas的示例项目geopandas:

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
)

您还可以指定所需的版本,参见 setuptools 文档。通常情况下,您需要确保所使用的版本是最新的(具有您所依赖的功能/错误修复)- 这里是我在 pep8radius 中实现的方法


请看我上面的更新。如果在调用“python setup.py develop”之前没有安装numpy,那么仅仅添加pandas是不起作用的。 - Achim
@Achim,当numpy不在install_requires中时,情况是这样吗? - Andy Hayden
这仍然无法与$ python setup.py develop一起使用,请参见numpy问题https://github.com/numpy/numpy/issues/2434。您必须使用pip安装numpy,而不是setuptools。这不会改变您的setup.py的外观,只会改变您调用它的方式。请参见下面的答案。 - Jason

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接