Scikit-Learn无法在OS X上安装:未声明的标识符和分配错误

时间:2013-07-31 22:33:22

标签: scikit-learn

在尝试在我的机器上安装scikit-learn时,我遇到了问题。我正在使用Homebrew的Python 2.7.5运行OS X 10.8.4,并且我安装了最新版本的Scipy和Numpy。

我尝试通过Pip安装scikit-learn以及克隆最新的源代码并从头开始构建 - 这是我每次尝试构建时都会得到的。知道这里发生了什么吗?

1 warning and 3 errors generated.
In file included from sklearn/feature_extraction/_hashing.c:258:
In file included from /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:15:
In file included from /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17:
In file included from /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1728:
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
 ^
sklearn/feature_extraction/_hashing.c:2439:15: error: assigning to 'int' from incompatible type 'void'
    __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              ^ ~~~~~~~~~~~~~~~~~~~
sklearn/feature_extraction/_hashing.c:4833:96: error: use of undeclared identifier 'PyBoolObject'
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                                                                                               ^
sklearn/feature_extraction/_hashing.c:4834:105: error: use of undeclared identifier 'PyComplexObject'
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                                                                                                        ^
1 warning and 3 errors generated.
error: Command "cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include -I/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include -I/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c sklearn/feature_extraction/_hashing.c -o build/temp.macosx-10.8-x86_64-2.7/sklearn/feature_extraction/_hashing.o" failed with exit status 1

2 个答案:

答案 0 :(得分:0)

升级到OSX 10.9 Mavericks后,我遇到了相同的构建问题。我通过运行来解决它:

xcode-select --install

更新XCode命令行工具。

我还用自制软件库升级了所有文件:

brew update
brew doctor
# fix all reported issues
brew upgrade

我必须卸载并重新安装以前针对C ++标准库的不兼容版本构建的一些依赖项。

答案 1 :(得分:0)

我在OSX 10.9 Mavericks上有类似的问题,也许它会帮助你OSX 10.8.4,或者在将来升级你的系统时。基于this answer并在进一步的研究中,我了解到您需要安装XCode命令行工具,这通常是在终端上运行的:

xcode-select --install

如果有效,请在本答案结尾处直接进入Homebrew步骤。但是,有些用户(就像我自己)可能在运行时遇到了麻烦,因为命令行工具现在随Xcode一起提供,而且不再可用。它可能会说:

  

“无法安装该软件,因为它目前无法从软件更新服务器获得。”

事实证明,升级或重新安装Xcode也可能无法正常工作,显然它并非以这种方式为我提供。幸运的是,还有另一种获取此命令行工具的方法(我读了here):

  1. 打开Xcode
  2. 在应用程序菜单项“Xcode”中选择Open Developer Tool>更多开发者工具......
  3. 这会将您带到一个拥有大量软件的网站。继续下载并安装“命令 适用于Xcode的Line Tools(OS X Mavericks) - 2013年10月下旬“。
  4. 如果您不是Mavericks用户,您也可以找到自己的版本。
  5. 然后您再次尝试安装Scikit-Learn。如果它仍然没有帮助,Xcode可能没有指向正确的位置。你试试这个(来源here):

    sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    

    或那个(来源here):

    sudo xcode-select -switch /Library/Developer/CommandLineTools
    

    Xcode.app的第一个是为我工作的那个。通过这种方式,你肯定会阻止Git命令行也会遇到的另一个问题,这会在下一步和最后一步中给你带来麻烦:Homebrew。这是因为Homebrew依赖于Git才能正常工作。

    Homebrew Step:

    brew update
    brew doctor
    # fix all reported issues
    brew upgrade
    

    如果仍然无法正常工作,请重新安装Homebrew(Homebrew homepage)并再次执行此操作。我希望这能解决你的问题:)