在Mac OS Lion上为Python3构建numpy / scipy

时间:2012-03-08 17:26:07

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

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

我已成功使用pip来安装numpy,scipy和matplotlib,并且它们与Python2.7配合得很好,但在Python3中输入import numpy会调出No module named numpy。我已经尝试直接下载源代码,然后运行'python3 setup.py build',但是我收到了各种错误警告,其中一些是红色的,与fortran有关(例如'找不到可执行文件f95')。最终失败的错误消息是'RuntimeError:Broken toolchain:无法链接一个简单的C程序',并且似乎与前一行'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安装可能会起作用,但我不知道该怎么做。有没有人对我如何进行有任何建议?感谢。

3 个答案:

答案 0 :(得分:4)

我遇到了同样的问题 scipy / sparse / linalg / dsolve / superlumodule.c:268:9:错误:非空函数'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;
确实有效吗

答案 1 :(得分:1)

我在这个问题上取得了一些进展,Ned Deily在pythonmac邮件列表上提供了很多帮助。我现在可以为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 

答案 2 :(得分:0)

我遇到了这个问题,其中一个对它进行了排序 - 不确定哪一个,但我包括两者的完整性:

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

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