如何在 MacOS 上的 python 中安装 xgboost?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39315156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install xgboost in python on MacOS?
提问by aman sanduja
I am a newbie and learning python. Can someone help me- how to install xgboost in python. Im using Mac 10.11. I read online and did the below mentioned step, but not able to decode what to do next:
我是新手,正在学习python。有人可以帮助我 - 如何在 python 中安装 xgboost。我使用的是 Mac 10.11。我在线阅读并执行了下面提到的步骤,但无法解码下一步要做什么:
pip install xgboost -
回答by Bryan Butler
It's a little more complicated if you want to use multi-threading. For the record, I am using a Mac with OS X 10.10 (Yosemite). It took me a while to work through the various issues, but it is now running nicely in my Anaconda (Py36) environment.
如果你想使用多线程,那就有点复杂了。作为记录,我使用的是装有 OS X 10.10 (Yosemite) 的 Mac。我花了一段时间来解决各种问题,但它现在在我的 Anaconda (Py36) 环境中运行良好。
For multi-threading you need to do the following first (install homebrew if you have not done so):
对于多线程,您需要先执行以下操作(如果您还没有这样做,请安装自制软件):
brew install gcc --without-multilib
You might get some warnings to unlink directories or delete them if you have other versions installed; follow the warnings/instructions.
如果您安装了其他版本,您可能会收到一些取消链接目录或删除它们的警告;遵循警告/说明。
Next get the xgboost files from Github. I downloaded it to Anaconda/pkgs
directory.
接下来从 Github 获取 xgboost 文件。我把它下载到Anaconda/pkgs
目录。
git clone --recursive https://github.com/dmlc/xgboost
The next series of steps differ from the documentation on the xgboost site, and I cobbled it together from lots of sources and also experimenting. The problem is that some key lines in the make files are commented out and also not fully specified.
接下来的一系列步骤与 xgboost 站点上的文档不同,我从大量来源拼凑起来并进行了试验。问题是 make 文件中的一些关键行被注释掉了,也没有完全指定。
cd xgboost; cp make/config.mk ./config.mk
Now, use your favorite editor (I used vi), and go into the file that you copied from /make
to /xgboost
现在,用你喜欢的编辑器(我用VI),并进入该文件,您从复制/make
到/xgboost
vi config.mk
Uncomment the lines near the top of the file:
取消注释文件顶部附近的行:
export CC = gcc
export CC = gcc
export CXX = g++
export CXX = g++
Change them to the following:
将它们更改为以下内容:
export CC = gcc-6
export CXX = g++-6
It is possible that simply uncommenting the lines solves the problem. It did not for me; I needed to add the -6
to both lines. Save the file.
简单地取消注释行可能会解决问题。它不适合我;我需要将-6
加到这两行。保存文件。
Also, make changes to the file xgboost/Makefile
; change lines:
另外,对文件进行更改xgboost/Makefile
;更改线路:
export CC = $(if $(shell which clang), clang, gcc)
...
...
export CXX = $(if $(shell which clang++), clang++, g++)
to the following:
到以下几点:
export CC = $(if $(shell which clang), clang, gcc-6)
...
...
export CXX = $(if $(shell which clang++), clang++, g++-6)
Again, I used vi for this editing.
同样,我使用 vi 进行此编辑。
Save the file and now you need to run a cleaning step since you changed the Makefile.
保存文件,现在您需要运行清洁步骤,因为您更改了 Makefile。
make clean_all && make -j4
This should configure it cleanly and build the library. You still need to install it.
这应该干净地配置它并构建库。您仍然需要安装它。
cd python-package; python setup.py install
Now restart Python/Anaconda and you should be able to import the library.
现在重新启动 Python/Anaconda,您应该能够导入该库。
回答by Adrien Renaud
For a newbie learning python and Machine Learning on Mac, I would strongly recommand to install Anaconda first (install doc).
对于在 Mac 上学习 Python 和机器学习的新手,我强烈建议先安装 Anaconda(安装文档)。
Anaconda is a freemium open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment.
Anaconda 是 Python 和 R 编程语言的免费增值开源发行版,用于大规模数据处理、预测分析和科学计算,旨在简化包管理和部署。
If you installed Anaconda for Python 2.7, then you should have no troubles installing XGBoost with:
如果您为 Python 2.7 安装了 Anaconda,那么安装 XGBoost 应该没有问题:
conda install -c aterrel xgboost=0.4.0
If you already have Anaconda installed and that your pip XGBoost installation failed, you should try:
如果您已经安装了 Anaconda 并且您的 pip XGBoost 安装失败,您应该尝试:
conda remove xgboost
conda install -c aterrel xgboost=0.4.0
回答by PritamJ
FOR PYTHON 2.7
对于 Python 2.7
$ conda install -c aterrel xgboost=0.4.0
OR
或者
$ conda install -c biconda xgboost=0.6a2
FOR PYTHON 3.6
对于 Python 3.6
$ brew install gcc@5
$ pip install xgboost
回答by ébe Isaac
For Python-3.x, do the following in Mac
对于 Python-3.x,请在 Mac 中执行以下操作
Make sure gcc-6 (and g++-6) is installed, if not do so with
确保安装了 gcc-6(和 g++-6),如果没有安装
brew install gcc
Then, do the following
然后,执行以下操作
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost/
make -j4
cd python-package
python3 setup.py install
If you are using Anaconda and haven't yet configured your path to use the binaries in ~/anaconda/bin
, then run the last line as
如果您正在使用 Anaconda 并且尚未配置您的路径以使用 中的二进制文件~/anaconda/bin
,则运行最后一行
/path/to/anaconda/bin/python3 setup.py install
/path/to/anaconda/bin/python3 setup.py install
回答by A. Attia
I followed Bryan Butler's answerand it worked, I just needed to make some changes:
我遵循了 Bryan Butler 的回答并且它起作用了,我只需要进行一些更改:
gcc-7
/g++-7
instead ofgcc-6
/g++-6
.- While running
make clean_all && make -j4
I had an error withas
. So, I just had to runexport PATH=/usr/bin:$PATH
and it worked!
gcc-7
/g++-7
而不是gcc-6
/g++-6
。- 在运行时
make clean_all && make -j4
我有一个错误as
。所以,我只需要运行export PATH=/usr/bin:$PATH
它就可以了!
回答by rossinnes
If you have anaconda installed, this worked for me:
如果您安装了 anaconda,这对我有用:
Simply type in the terminal:
只需在终端输入:
conda install -c conda-forge xgboost
回答by Christoffer M?ckelind
Im running Mac OS Mojave 10.14.5 and following the "advanced method" instructions for Mac OS at https://xgboost.readthedocs.io/en/latest/build.html#worked for me. In short:
我运行 Mac OS Mojave 10.14.5 并遵循https://xgboost.readthedocs.io/en/latest/build.html#上 Mac OS 的“高级方法”说明为我工作。简而言之:
brew install cmake
brew install gcc@8
git clone --recursive https://github.com/dmlc/xgboost
mkdir xgboost/my_build
cd xgboost/my_build
CC=gcc-8 CXX=g++-8 cmake ..
make -j4
cd ../python_package
python3 setup.py install
回答by Anna Veronika Dorogush
You can pip install catboost. It is a recently open-sourced gradient boosting library, it has similar interfaces and is more accurate, than XGBoost, faster and has categorical features support out of the box. Here is the site of the library: https://catboost.yandex
您可以 pip install catboost。它是最近开源的梯度提升库,它具有类似的接口,并且比 XGBoost 更准确、更快,并且具有开箱即用的分类特征支持。这是图书馆的网站:https: //catboost.yandex
回答by Zitong Lian
All the other ways described here failed in my case. I managed to install by following the official installation described here: http://xgboost.readthedocs.io/en/latest/build.html#building-on-macos
在我的情况下,这里描述的所有其他方法都失败了。我设法按照此处描述的官方安装进行安装:http: //xgboost.readthedocs.io/en/latest/build.html#building-on-macos
My system is MacOS Serria so I followed the instruction of "Building on macOS".
我的系统是 MacOS Serria,所以我按照“在 macOS 上构建”的说明进行操作。
However, instead of "replacing these two lines into(5 or 6 or 7; depending on your gcc-version" w.r.t. the config.mk file, I did:
但是,我没有“将这两行替换为(5 或 6 或 7;取决于您的 gcc 版本”)写入 config.mk 文件,而是:
export CC = gcc-5
export CXX = g++-5
Even though gcc-version
showed Apple LLVM version 9.0.0
.
尽管gcc-version
显示Apple LLVM version 9.0.0
.
After that by following the official instruction of "Python Package Installation" I was able to run the package in Python.
之后,按照“Python 包安装”的官方说明,我能够在 Python 中运行该包。