如何在setup.py中处理对scipy的依赖

Bjö*_*lex 15 python setuptools scipy python-2.7

我正在尝试创建一个setup.py依赖于SciPy的项目.以下setup.py重现:

setup(
    name='test',
    version='0.1',
    install_requires=['scipy']
)
Run Code Online (Sandbox Code Playgroud)

使用python setup.py develop它安装时会生成以下错误:

ImportError: No module named numpy.distutils.core
Run Code Online (Sandbox Code Playgroud)

但是,当我安装scipy时pip,它是从一个轮子安装它,它工作得很好.

所以,我的问题是,我如何创建一个setup.py取决于SciPy?为什么不setuptools安装轮子的依赖?使用Python 3时这会更好吗(我们计划无论如何都要迁移,所以如果它在那里工作,我会等到迁移完成后).

我在Mac OS X 10.10.1上使用Python 2.7.8 setuptools3.6和pip1.5.6.

Ale*_*ece 2

最终,这对我有用:

#!/usr/bin/env python

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext

#
# This cludge is necessary for horrible reasons: see comment below and
# http://stackoverflow.com/q/19919905/447288
#
class build_ext(_build_ext):
    def finalize_options(self):
        _build_ext.finalize_options(self)
        # Prevent numpy from thinking it is still in its setup process:
        __builtins__.__NUMPY_SETUP__ = False
        import numpy
        self.include_dirs.append(numpy.get_include())

setup(
    #
    # Amazingly, `pip install scipy` fails if `numpy` is not already installed.
    # Since we cannot control the order that dependencies are installed via
    # `install_requires`, use `setup_requires` to ensure that `numpy` is available
    # before `scipy` is installed.
    #
    # Unfortunately, this is *still* not sufficient: `numpy` has a guard to
    # check when it is in its setup process that we must circumvent with
    # the `cmdclass`.
    #
    setup_requires=['numpy'],
    cmdclass={'build_ext':build_ext},
    install_requires=[
        'numpy',
        'scipy',
    ],
    ...
)
Run Code Online (Sandbox Code Playgroud)