2014-11-19 3 views
14

Ich versuche, ein setup.py für ein Projekt zu erstellen, das von SciPy abhängt. Die folgende setup.py reproduziert diese:Wie man die Abhängigkeit von scipy in setup.py behandelt

setup(
    name='test', 
    version='0.1', 
    install_requires=['scipy'] 
) 

Wenn diese python setup.py develop mit der Installation erzeugt es den folgenden Fehler:

ImportError: No module named numpy.distutils.core 

Allerdings, wenn ich scipy mit pip installieren, es von einem Rad installiert, und es funktioniert Alles gut.

Also, meine Fragen ist, wie kann ich eine setup.py erstellen, die auf SciPy abhängt? Warum werden setuptools Abhängigkeiten von Rädern nicht installiert? Würde dies bei der Verwendung von Python 3 besser funktionieren (wir planen sowieso eine Migration, wenn es dort funktioniert, warte ich einfach, bis die Migration abgeschlossen ist).

Ich benutze Python 2.7.8 unter Mac OS X 10.10.1 mit setuptools 3.6 und pip 1.5.6.

+1

'install_requires' stört mich immer; Ich musste manchmal herumarbeiten, aber ich habe hier keine Lösung. Ist 'install_requires = ['numpy', 'scipy']' help? – Evert

+1

Und vielleicht diese [SO Frage & Antwort] (http://stackoverflow.com/questions/2087148/cani-i-use-pip-instead-of-easy-install-for-python-setup-py-install-dependen)) help: das lässt 'pip' sich um die Abhängigkeiten kümmern, während Sie ansonsten im Wesentlichen das gleiche Verhalten wie' python setup.py develop 'erhalten. – Evert

+0

Es tut es nicht. Anscheinend ist die Reihenfolge, in der 'setuptools' Abhängigkeiten installiert, nicht angegeben, daher versucht es SciPy zuerst zu installieren und schlägt fehl. Seltsamerweise, wenn ich Tests mit [tox] (http://tox.readthedocs.org) (ohne die einfachste "tox.ini") durchführe, wird es gut installiert. –

Antwort

2

Letztlich war das für mich:

setup(
    name='test', 
    version='0.1', 
    setup_requires=['numpy'], 
    install_requires=['scipy'] 
) 

Hinweis: Auch Fortran Compiler erforderlich scipy zu bauen

#!/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', 
    ], 
    ... 
) 
2

Verwendung setup_requires Parameter numpy vor scipy zu installieren. Sie können es über brew installieren:

brew install gcc 

P. S. Wenn Sie haben AttributeError: 'module' object has no attribute 'get_include' werfen Sie einen Blick auf Why doesn't setup_requires work properly for numpy? SO Frage, es wird angenommen, dass das Problem zu beheben.

+0

Wie funktioniert das? Insbesondere, wann wird die 'run'-Methode ausgeführt? –

+0

@AlexReece danke für das Hinzeigen, diese Methode und Haken ist obskur ... Ich habe es entfernt. –