xgboost MAC系统、LINUX、widonws下安装

来源:互联网 发布:仁化县网络问政 编辑:程序博客网 时间:2024/06/05 03:15

第一次写博客,xgboost好用但安装的坑比较多,在此写篇博客给大家参考。

一.MAC osx 上装xgboost

     1.安装Python环境 MAC OS 已在带Python 2.7,此步请忽略。

     2.安装Homebrew Homebrew类似于ubuntu中的apt-get和centos中的yum,是OSX里面的一个非常有用软件安装工具. 安装这个软件的目的在于更新gcc版本,官方文档中    说最新的gcc版本才使XGBoost支持多线程。 直接将上述代码粘贴至终端即可安装,下同(除非特别说明)。

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
     3.安装gcc-6 (由于最新的gcc是gcc-7,而XGBoost对gcc-7支持不太好,所以还是安装gcc-6) 这个比较耗时,可能需要半个小时到一个小时,请耐心等待。
brew install gcc@6 --without-multilib 
     4.用刚安装的gcc替代OS缺省的gcc 这一步官方安装文档中没有说明。 用命令
gcc -v

              查看系统默认gcc,发现不是刚安装的gcc-6。 先删除系统默认的gcc(可以在删除之前将这些文件备份,这样可以恢复) 显示如下

cd /usr/bin/rm cc gcc c++ g++

            依次给gcc,g++,c++,cc添加软链接

ln -s /usr/local/Cellar/gcc\@6/6.3.0/bin/gcc-6 ccln -s /usr/local/Cellar/gcc\@6/6.3.0/bin/gcc-6 gccln -s /usr/local/bin/c++-6 c++ln -s /usr/local/bin/g++-6 g++

           进入用户根目录,

cd ~

           用vim打开.bash_profile文件,在PATH路径下添加以下路径,即在文件中添加一行:

export PATH="/usr/local/Cellar/gcc@6/6.3.0/bin/:/usr/local/Cellar/gcc@6/6.3.0/lib:$PATH"

          再用命令

gcc -v

             显示如下:

Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/6.3.0_1/libexec/gcc/x86_64-apple-darwin16.4.0/6.3.0/lto-wrapper Target: x86_64-apple-darwin16.4.0 Configured with: ../configure --build=x86_64-apple-darwin16.4.0 --prefix=/usr/local/Cellar/gcc/6.3.0_1 --libdir=/usr/local/Cellar/gcc/6.3.0_1/lib/gcc/6 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew GCC 6.3.0_1 --without-multilib' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-nls --disable-multilib Thread model: posix gcc version 6.3.0 (Homebrew GCC 6.3.0_1 --without-multilib)

           终于将默认gcc替换成刚安装的gcc-6。 

          5.从Git上下载XGBoost源码

git clone --recursive https://github.com/dmlc/xgboost 
     6.编译XGBoost的源码
cd xgboostcp make/config.mk ./config.mkmake -j4

      如果没有一直警告gcc不支持多线程,则表示这一步顺利完成.安装Python版本

cd python-packagesudo python setup.py install
     7.测试安装是否成功 在Python编程环境下,输入
import xgboost as xgb

      如果没有报错,则大功告成。


二.linux上装xgboost

1.pip install xgboost报错选2

2.sudo apt-get update再报错选3

3.sudo -H pip install --pre xgboost


三.windows下安装xgboost
     1.python3.5以上版本
http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost在以上网站找对应版本安装
pip install D:\xgboost-0.6-cp35-cp35m-win_amd64.whl  
     (install后面为你下载保存位置加上下载的版本)
2.python2.7
     按以下博客进行安装:
     http://blog.csdn.net/u010180815/article/details/53977700
     出现如下问题:
     
转以下博客
http://blog.csdn.net/yueshibin/article/details/52750640#comments(注:python2.7下载0.46版本的xgboost)