gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:08:30 24 4
gpt4 key购买 nike

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

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

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

ImportError: No module named numpy.distutils.core

但是,当我使用 pip 安装 scipy 时,它是通过轮子安装的,并且工作正常。

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

我在 Mac OS X 10.10.1 上使用 Python 2.7.8 以及 setuptools 3.6 和 pip 1.5.6。

最佳答案

最终,这对我有用:

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

关于python - 如何处理 setup.py 中对 scipy 的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27021270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com