在Python中安装scikit-learn时遇到的问题

8
我正在尝试安装Python包scikit-learn,但一直出现错误。 我尝试过:
 pip install scikit­-learn

错误信息如下。我的安装出了什么问题?
compile options: '-I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include -c'

c++: sklearn/svm/src/libsvm/libsvm_template.cpp

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

error: Command "c++ -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include -c sklearn/svm/src/libsvm/libsvm_template.cpp -o build/temp.macosx-10.9-intel-2.7/sklearn/svm/src/libsvm/libsvm_template.o" failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/tmp/pip_build_root/scikit-learn/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-GYuqQN-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/tmp/pip_build_root/scikit-learn
Storing debug log for failure in /Users/johnkuk/Library/Logs/pip.log

我也尝试了几种不同的方法来安装这个包。从easy_install安装时,我也收到了以下错误信息。

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: Setup script exited with error: Command "c++ -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include -c /private/tmp/easy_install-oD3dwa/scikit-learn-0.14.1/sklearn/svm/src/libsvm/libsvm_template.cpp -o build/temp.macosx-10.9-intel-2.7/private/tmp/easy_install-oD3dwa/scikit-learn-0.14.1/sklearn/svm/src/libsvm/libsvm_template.o" failed with exit status 1
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/distutils/misc_util.py:252: RuntimeWarning: Parent module 'numpy.distutils' not found while handling absolute import
  from numpy.distutils import log

这看起来像是您的LLVM安装出了问题。您确定您拥有最新版本的XCode CLI工具吗? - inspectorG4dget
scikit-learn从NumPy获取其编译器参数,看起来您的NumPy是使用GCC编译的,因此您需要使用该编译器进行编译。 - Fred Foo
1个回答

6

今天我也遇到了同样的问题,尝试了很多方法后,最终解决问题的方法是在使用pip安装之前设置一些环境变量:

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

然后使用sudo安装:

sudo -E pip install -U scikit-learn

看起来与xcode更新有问题(对我来说是5.1.1),它不接受“-mno-fused-madd”作为参数,之前它会抛出警告,现在则是错误,前两个命令忽略未使用的参数,这些参数与抛出错误的参数相同。

希望对您有所帮助,欢迎任何评论/更正。


2
也适用于我,正在运行Mavericks。 - themaestro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接