2014-11-19 2 views
14

SciPy에 의존하는 프로젝트에 setup.py을 만들려고합니다.setup.py에서 scipy에 대한 의존성을 처리하는 방법

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

는 다음과 같은 오류 발생 python setup.py develop를 사용하여이를 설치 : 다음 setup.py이 재현 pip를 사용 scipy 내가 설치할 때, 그러나

ImportError: No module named numpy.distutils.core 

, 그것은 바퀴에서 설치하고 작동 잘 됐네.

제 질문은 SciPy에 따라 달라지는 setup.py을 어떻게 만듭니 까? setuptools이 바퀴에서 종속성을 설치하지 않는 이유는 무엇입니까? 파이썬 3을 사용할 때 이것이 더 효과적일까요? (우리는 어쨌든 마이 그 레이션 할 계획입니다. 그래서 거기서 작동한다면, 마이 그 레이션이 완료 될 때까지 기다릴 것입니다).

Mac OS X 10.10.1에서 setuptools 3.6 및 pip 1.5.6으로 Python 2.7.8을 사용하고 있습니다.

+1

'install_requires'는 항상 나를 귀찮게합니다. 나는 때때로 그 문제를 해결해야했지만 여기에는 해결책이 없습니다. 'install_requires = [ 'numpy', 'scipy']'도움이됩니까? – Evert

+1

그리고 아마도이 [그래서 질문 및 답변] (http://stackoverflow.com/questions/2087148/can-i-use-pip-instead-of-easy-install-for-python-setup-py-install-dependen) help :'pip'가 의존성을 처리하게하고,'python setup.py develop'와 본질적으로 같은 행동을합니다. – Evert

+0

그렇지 않습니다. 분명히'setuptools'가 의존성을 설치하는 순서가 명시되어 있지 않기 때문에 먼저 SciPy를 설치하려고 시도하고 실패합니다. 이상하게도, [tox] (http://tox.readthedocs.org)를 사용하여 (가장 기본적인'tox.ini '없이) 테스트를 실행하면 잘 설치됩니다. –

답변

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

사용 setup_requires 매개 변수 numpy 이전 scipy를 설치 :

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

: 또한 포트란 컴파일러가 scipy을 구축 할 필요가있다. 당신은 brew를 통해 설치할 수 있습니다 :

brew install gcc 

추신을AttributeError: 'module' object has no attribute 'get_include'Why doesn't setup_requires work properly for numpy?에 대한 질문을 가지고 있다면, 그 문제를 해결할 것으로 생각됩니다.

+0

어떻게 작동합니까? 특히'run' 메서드는 언제 실행됩니까? –

+0

@AlexReece 지적 해 주셔서 고맙습니다. 그 방법과 훅은 애매합니다 ... 나는 그것을 제거했습니다. –