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



在我的机器上安装scikit-learn时遇到了问题。我运行的是Homebrew的OS X 10.8.4和Python 2.7.5,我安装了最新版本的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

在升级到OSX 10.9 Mavericks后,我遇到了同样的构建问题。我通过运行解决了这个问题

xcode-select --install

以更新XCode命令行工具。

我还升级了所有的自制程序库:

brew update
brew doctor
# fix all reported issues
brew upgrade

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

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

xcode-select --install

如果有效,您可以直接进入答案末尾的自制步骤。然而,有些用户(比如我自己)可能会在运行时遇到问题,因为命令行工具现在是随Xcode提供的,不再以这种方式提供。它可能会说:

"无法安装软件,因为软件更新服务器当前不提供该软件。"

事实证明,升级或重新安装Xcode可能也不起作用,显然它不是以这种方式为我提供的。幸运的是,还有另一种方法可以获得这个命令行工具(我在这里阅读):

  1. 打开Xcode
  2. 在应用程序菜单项"Xcode"中,选择Open Developer Tool>More Developer Tools
  3. 这会把你带到一个有很多软件的网站。继续下载并安装"命令Xcode的Line Tools(OS X Mavericks)-2013年10月下旬"
  4. 如果你不是小牛队的用户,你也会找到自己的版本

然后您尝试再次安装Scikit Learn。如果仍然没有帮助,Xcode可能没有指向正确的位置。你可以试试这个(这里的来源):

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

或者(来源于此):

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

Xcode.app的第一个是对我有效的。通过这样做,你肯定可以防止Git命令行崩溃的另一个问题,这会在下一个也是最后一个步骤中困扰你:Homebrew。这是因为Homebrew依赖Git才能正常工作。

自制步骤:

brew update
brew doctor
# fix all reported issues
brew upgrade

如果仍然不起作用,请重新安装Homebrew(Homebrew主页)并重试。我希望这将解决您的问题:)

相关内容

  • 没有找到相关文章

最新更新