Installing Python 2.7 and XGBoost on OS X — the easy way

Note: this works for xgboost-0.6a2 and OS X Sierra (10.12.3).I have not tested it else where.

Install Brew and Python

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
# upgrade too if you can
brew upgrade
# install Python from brew is highly recommended
brew install python
Note: OS X does come with python (2.7.10) by default at /usr/bin/python but I would highly recommend brew over this.

Install Pip

# install from source code
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py
# show current pip version
pip --version
# upgrade pip
pip install --upgrade pip
Note: you can always do sudo easy_install pip like some other page suggested, but it will result in having to do sudo pip install package_name every time

Install GCC5 and then XGBoost

# grab your coffee after this command
brew install gcc5 # gcc6 would not work
# you might need to update these permissions:
sudo chown -R $USER /Library/Python/2.7/
# install xgboost (if you already have, reinstall it first)
pip install xgboost

— using gcc6 will lead you to the following error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/v7/6lt9nkjn2l5fydstthby_rn40000gn/T/pip-build-ZDRVmr/xgboost/setup.py", line 29, in <module>
LIB_PATH = libpath['find_lib_path']()
File "/private/var/folders/v7/6lt9nkjn2l5fydstthby_rn40000gn/T/pip-build-ZDRVmr/xgboost/xgboost/libpath.py", line 45, in find_lib_path
'List of candidates:\n' + ('\n'.join(dll_path)))
__builtin__.XGBoostLibraryNotFound: Cannot find XGBoost Libarary in the candicate path, did you install compilers and run build.sh in root path?
List of candidates:
/private/var/folders/v7/6lt9nkjn2l5fydstthby_rn40000gn/T/pip-build-ZDRVmr/xgboost/xgboost/libxgboost.so
/private/var/folders/v7/6lt9nkjn2l5fydstthby_rn40000gn/T/pip-build-ZDRVmr/xgboost/xgboost/../../lib/libxgboost.so
/private/var/folders/v7/6lt9nkjn2l5fydstthby_rn40000gn/T/pip-build-ZDRVmr/xgboost/xgboost/./lib/libxgboost.so
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/v7/6lt9nkjn2l5fydstthby_rn40000gn/T/pip-build-ZDRVmr/xgboost/