【问题标题】:Install numpy + pandas as dependency in setup.py在 setup.py 中安装 numpy + pandas 作为依赖项
【发布时间】:2014-11-03 09:15:15
【问题描述】:

通过 setuptools 安装 numpy + pandas 作为 setup.py 中的依赖项对我不起作用。这与缺少依赖关系无关。如果我通过pip install numpy 安装numpy,然后python setup.py develop 一切正常。如果我正确理解setuptools 文档,则所有软件包都是先构建然后安装的。因此,numpy 已构建,但在 pandas 构建时未安装。

作为一种解决方法,我将numpy 添加到我的setup_requires。这很好用,但显然不是一个非常干净的解决方案。

有人知道通过 setuptools 安装 numpy + pandas 的干净解决方案(仅限 Linux 即可)吗?

更新:

依赖配置通过

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 是否显式添加没有区别。

【问题讨论】:

  • 您如何将其声明为依赖 atm? (不工作的方式。)

标签: python numpy pandas setuptools


【解决方案1】:

请参考未解决的问题https://github.com/numpy/numpy/issues/2434

这是 numpy 中的一个已知错误,因为它与 setuptools 相关。

正如那里所讨论的,使用$ pip install -e . 而不是$ python setup.py develop——结果相同,但避免了这个问题。

【讨论】:

    【解决方案2】:

    这些应该用 install_requires kwarg 的 setup 声明。这里是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
    )
    

    您还可以指定所需的版本,请参阅 setuptools docs,因为您通常需要确保版本是最新的(具有您依赖的功能/错误修复) - 这里是 how I do that in pep8radius.

    【讨论】:

    • 见我上面的更新。如果在调用 python setup.py develop 之前未安装 numpy,只需像您一样添加熊猫,对我不起作用。
    • @Achim 是 numpy not in install_requires 的情况吗?
    • 这仍然不适用于$ python setup.py develop,请参阅 numpy 问题github.com/numpy/numpy/issues/2434。您必须使用 pip 来安装 numpy,而不是 setuptools。这不会改变你的 setup.py 的样子,只是你如何称呼它。请参阅下面的答案
    猜你喜欢
    • 2015-01-10
    • 1970-01-01
    • 2022-01-15
    • 2012-02-01
    • 2021-01-14
    • 2017-03-18
    • 2015-01-04
    • 2013-07-19
    • 2014-05-03
    相关资源
    最近更新 更多