The most complete macos installation xgboost tutorial in history

Project github address: bitcarmanlee easy-algorithm-interview-and-practice
welcome everyone to star, leave a message, and learn and progress together

0. Preface

I have not installed xgboost on my macos. Recently, due to work needs, I want to install xgboost on macos.
I thought it was a very simple thing, but I didn’t expect that it took some twists and turns, so I recorded it specially

1. Failed to install directly

Use it directly at the beginning

pin install xgboost

There is nothing wrong with the installation process. However, after the installation was completed, problems occurred during use.

import xgboost as xgb

After importing xgboost, report an error directly

xgboost.core.XGBoostError: XGBoost Library (libxgboost.dylib) could not be loaded.
Likely causes:
  * OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libgomp.so for UNIX-like OSes)
  * You are running 32-bit Python on a 64-bit OS
....

I checked the reasons, and the general reasons are as follows: The
Xgboost model itself supports multi-threaded operation, that is, multiple CPU threads are used for training;
however, the default apple clang compiler does not support openmp, so using the default compiler will disable multi-threading.

2. Solution 1

I searched the online solutions again, most of the routines are like this:
first upgrade homebrew, then install a higher version of gcc through homebrew, then go to gitclone xgboost source code, build source code, and install.

It turns out that whether it is upgrading homebrew, or installing gcc, gitclone source code, every step is as difficult as the sky, old folks understand.

So this is a feasible way, but it can be called hell difficulty, so I just gave up.

3. Solution 2

During the search, I found that an old man directly gave a line of code to solve the problem.

conda install py-xgboost

There are a few posts that reflect that the method is simple and rude and easy to use, so I tried it with the idea of ​​giving it a try.
As a result, conda dropped the link.

Solving environment: failed with initial frozen solve. Retrying with flexible solve.
......

4. Connect the conda chain

The conda problem is obviously a source problem. I couldn't help but sigh again... After
searching for a long time, I tried N many sources, and found that none of them worked.
Finally, I carefully read the anaconda page of the Tsinghua open source mirror station, and with the mentality of giving it a try, paste the configuration on the official website to the local .condarc file

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

Anaconda link of Tsinghua open source mirror station:
Tsinghua anaconda mirror

Seeing here is actually a little bit emotional, the domestic IT industry is in full swing, but this important and basic thing is actually a school student who is spontaneously maintaining it according to his own hobbies...

5. You're done

After modifying the conda configuration, execute the installation command

conda install py-xgboost

Found that you're done, you can run the xgb-related code locally.
Later, I have time to look up a little bit about what is special about this py-xgboost.

Guess you like

Origin blog.csdn.net/bitcarmanlee/article/details/112126754