安装xgboost

这两天做模型集成需要用到xgboost,记录一下自己本机编译时Google到的小坑。

查看系统的gcc版本:

1
2
3
4
5
6
➜ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

此输出这说明系统路径中没有真正的gcc,有的只是Xcode指向Clang的连接。
(参考:how to find gcc version on mac

列出macports中安装的gcc:

1
2
3
4
5
➜ port select --list gcc
Available versions for gcc:
mp-gcc5
mp-gcc6
none (active)

按照官方帮助,路径在/opt/local/bin/下找到名为gcc-mp-5g++-mp-5的程序,运行:

1
2
3
export CC=/opt/local/bin/gcc-mp-5
export CXX=/opt/local/bin/g++-mp-5
pip install xgboost

(参考:How to use the gcc installed in macports?
在环境中运行import xgboost as xgb测试通过。

如果确实需要修改系统中gcc指向的编译器,可以使用sudo port select --set gcc mp-gcc5
(参考:http://www.ficksworkshop.com/blog/post/installing-gcc-on-mac)

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×