【问题标题】:Building numpy/scipy for Python3 on Mac OS Lion在 Mac OS Lion 上为 Python3 构建 numpy/scipy
【发布时间】:2012-03-26 04:37:08
【问题描述】:

我无法让 NumpyScipy 在 MAC OSX Lion 上使用 Python3。

我已经成功使用 pip 安装了 numpy、scipy 和 matplotlib,它们在 Python2.7 上运行良好,但在 Python3 中键入 import numpy 会弹出 No module named numpy。我试过直接下载源代码,然后运行'python3 setup.py build',但我收到各种错误警告,其中一些与fortran有关(例如'Could not locate executable f95')。最后出现失败的错误消息是“RuntimeError: Broken toolchain: cannot link a simple C program”,似乎与上一行“sh: gcc-4.2: command not found”有关。

Scipy website 表明 c 编译器可能存在问题,但使用 pip 安装 python2.7 并没有出现同样的问题。我已按照网站上有关更改编译器的说明进行操作,但这没有任何区别。

我也尝试过从虚拟环境安装:

mkvirtualenv -p python3.2 test1
pip install numpy

但是Command python setup.py egg_info failed with error code 1 in /Users/Eddy/.virtualenvs/test1/build/numpy 失败了

我考虑过将 python3 设为默认值,然后我认为 pip 安装可能有效,但我不知道该怎么做。有人对我如何进行有任何建议吗?谢谢。

【问题讨论】:

  • 我现在已经让 scipy 等人在 Python2.7 上工作,我按照这里的说明进行操作:thisisthegreenroom.com/2011/…,尽管对于 scipy 本身,我必须 a) 自己下载源代码,b) 安装 umfpack通过键入“brew install umfpack”,c) 从 scipy 目录运行“python setup.py build”和“python setup.py install”。
  • 同样的技术在 python3 上没有成功。转到 numpy 目录并键入“python3 setup.py build”会给出消息“这是要运行的错误 setup.py 文件”。打开 VirtualEnv 测试和“pip install numpy”也失败,出现 egg_info 错误代码 1,不管是什么。
  • 我已经成功地为 Linux 上的 Python 3 从源代码构建了 numpy。我建议您获取源 tarball (on PyPI) 并尝试使用 setup.py。如果您收到“错误的 setup.py 文件”消息,则说明您使用了错误的 setup.py 文件;)。您需要源代码顶级目录中的那个。
  • 谢谢 Thomas,我已经下载了源代码(我尝试直接使用 tar,现在我尝试了 scipy.org/Installing_SciPy/Mac_OS_X 上推荐的 git clone)。我现在也在使用正确的 setup.py ;-) 现在,当我执行“python3 setup.py build”时,它在最终警告后失败:“RuntimeError: Broken toolchain: cannot link a simple C program”。这似乎与输出中显示“sh: gcc-4.2: command not found”的行相关联。还有红色的输出行抱怨:“Could not locate executable f95”(除其他外,但几乎都与fortran相关)。
  • scipy 网站 (scipy.org/Installing_SciPy/Mac_OS_X) 确实说 Lion 捆绑的 C 编译器有困难,我按照它的建议从 llvm-gcc-4.2 更改为 gcc-4.2,但我不是确定它是否有效。 “gcc -version”给了我:“i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1(基于 Apple Inc. build 5658)(LLVM build 2336.1.00)”+ 一些更多合法的东西。

标签: macos numpy python-3.x scipy importerror


【解决方案1】:

我遇到了同样的问题 scipy/sparse/linalg/dsolve/superlumodule.c:268:9:错误:非 void 函数“PyInit_superlu”应该返回一个值 [-Wreturn-type]

scipy 邮件列表中的某个人提出了以下建议:

what happens if you change the line 268 ( in scipy/sparse/linalg/dsolve/_superlumodule.c)

from 
return;

to 
return NULL;

果然成功了

【讨论】:

  • 我希望我能给你更多的支持。这现在也已在 github 上的 scipy (master) 中得到修复。
【解决方案2】:

在 pythonmac 邮件列表中 Ned Deily 的大力帮助下,我在这个问题上取得了一些进展。我现在可以为 python3 构建 numpy,但 scipy 仍然无法构建。

要安装 numpy: scipy 网站 (http://www.scipy.org/Installing_SciPy/Mac_OS_X) 建议使用三个键入命令来解决 C 编译器问题,但这些还不够,您还需要一个:

$ export CC=clang
$ export CXX=clang
$ export FFLAGS=-ff2c
$ export LDSHARED='clang -bundle -undefined dynamic_lookup \
-arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -g'

从源代码构建之后应该可以工作。详情请见here

构建 scipy 的问题: 我不知道这里的问题是什么,尽管我认为还是 C 编译器的问题。这是错误消息。我非常感谢您对此事的任何想法。

谢谢,艾迪

错误信息:

compiling C sources 

C compiler: clang -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk 

compile options: '-DNO_ATLAS_INFO=3 -DUSE_VENDOR_BLAS=1 -I/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m -c' 
extra options: '-msse3' 
clang: scipy/sparse/linalg/dsolve/_superlumodule.c 
In file included from scipy/sparse/linalg/dsolve/_superlumodule.c:18: 
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/arrayobject.h:15: 
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/ndarrayobject.h:17: 
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/ndarraytypes.h:1972: 
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API" [-W#warnings] 
#warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API" 
 ^ 
scipy/sparse/linalg/dsolve/_superlumodule.c:268:9: error: non-void function 'PyInit__superlu' should return a value [-Wreturn-type] 
        return; 
        ^ 
1 warning and 1 error generated. 
In file included from scipy/sparse/linalg/dsolve/_superlumodule.c:18: 
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/arrayobject.h:15: 
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/ndarrayobject.h:17: 
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/ndarraytypes.h:1972: 
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API" [-W#warnings] 
#warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API" 
 ^ 
scipy/sparse/linalg/dsolve/_superlumodule.c:268:9: error: non-void function 'PyInit__superlu' should return a value [-Wreturn-type] 
        return; 
        ^ 
1 warning and 1 error generated. 
error: Command "clang -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -DNO_ATLAS_INFO=3 -DUSE_VENDOR_BLAS=1 -I/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m -c scipy/sparse/linalg/dsolve/_superlumodule.c -o build/temp.macosx-10.6-intel-3.2/scipy/sparse/linalg/dsolve/_superlumodule.o -msse3" failed with exit status 1 

【讨论】:

  • 你有没有让这个工作?我能够在 10.7 上使用 python3 安装 scipy 0.10.1,而无需做任何特别的事情(除了下载源代码并使用 setup.py install 而不是 pip/easy_install,并使用自制软件中的 gfortran)。
  • 不,我还没有设法让它工作。您是否必须以其他方式指定 gfortran?我现在对 python 2 很满意,但我可能会在今年晚些时候新的 scipy 发布时再试一次。
  • 不,我很确定它完全没有做任何事情(设置环境变量或任何东西)就可以工作。
【解决方案3】:

我遇到了这个问题,其中一个对它进行了排序 - 不确定是哪一个,但为了完整起见,我将两者都包括在内:

  1. 我的 .bash_profile “export CC=gcc-4.2”中有这个,这可能是以前 OS X 编译问题的某种破解,我删除了它。
  2. 通过我的 XCode 安装从这里 https://github.com/kennethreitz/osx-gcc-installer/ 安装独立的 GCC

启动了一个新的终端窗口,pip install numpy 工作正常

【讨论】:

    猜你喜欢
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多