My Jupyter notebook's python kernel keeps dying when attempting to train an XGBoost logistic classifier. Previously, I have run all of the following code successfully. Presently, there are issues. First, I will show you the code chunk that I am able to run successfully:

import xgboost as xgb
xgtrain = xgb.DMatrix(data = X_train_sub.values, label = Y_train.values)       # create dense matrix of training values
xgtest  = xgb.DMatrix(data = X_test_sub.values,  label = Y_test.values)        # create dense matrix of test values
param   = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic'}  # specify parameters via map

where my data is small:

(1365, 18)

however, my notebook's kernel keeps dying on this chunk:

xgmodel = xgb.train(param,  xgtrain, num_boost_round = 2)                      # train the model
predictions = xgmodel.predict(xgtest)                                          # make prediction
from sklearn.metrics import accuracy_score                                   
accuracy = accuracy_score(y_true = Y_test, 
                          y_pred = predictions.round(), 
                          normalize = True) # If False, return # of correctly classified samples. Else, return fraction of correctly classified samples
print("Accuracy: %.2f%%" % (accuracy * 100.0))

As stated before, I have been able to run both chunks successfully before. I have shut down all other notebooks and restarted my computer without luck. I am launching jupyter through Anaconda Navigator on a Macbook Pro.


To further debug, I used Terminal CLI and ran:

  1. conda install runipy
  2. runipy MyNotebook.ipynb

which was very helpful, because it produced the following error message that I could then Google:

OMP: Error #15: Initializing libomp.dylib, but found libiomp5.dylib already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/

I found this thread:


Which shows others having the same problem on MacOS. I also suspected the problem being linked to matplotlib somehow because running any cell with matplotlib related code somehow causes the xgb.train to kill the kernel.

  • $\begingroup$ What is the shape of xgtrain? It might be possible that python is running out of memory. $\endgroup$
    – Ankit Seth
    Jul 4, 2018 at 5:29
  • $\begingroup$ What are your machine specs... It's actually weird as you can't run out of memory with such a small dataset... I guess the error is somewhere else.. You have tried restarting the kernel also, so another option to try it out is run it in raw python as a script and report back... $\endgroup$
    – Aditya
    Jul 4, 2018 at 9:13
  • $\begingroup$ @AnkitSeth not sure how to find the shape of an xgb.DMatrix. $\endgroup$ Jul 4, 2018 at 11:25
  • $\begingroup$ @Aditya it's a new Macbook Pro so should be pretty powerful. Yes, I have restarted the kernel probably a few dozen times trying to fix the problem. $\endgroup$ Jul 4, 2018 at 11:26
  • $\begingroup$ You can try downgrading the version of xgboost to 0.80 $\endgroup$
    – Zoom Deres
    Feb 4, 2019 at 9:20

3 Answers 3


When I selected a cell beneath my xgboost training cell, then selected: Cells --> Run All Above, the kernel would always die on the xgboost training cell. This happened probably 40-50 times in a row.

When I ran the same cells one-by-one, it completed fine on the first time I tried this and every time after.

  • $\begingroup$ Now this is really weird, try running your whole code in a .py file directly via ` python filename.py` $\endgroup$
    – Aditya
    Jul 4, 2018 at 14:54
  • 1
    $\begingroup$ @Aditya yeah. good idea. i updated my original post w/ more info and what i found as a result of your suggestion. $\endgroup$ Jul 4, 2018 at 23:52
  • $\begingroup$ Pardon me I ain't a MAC user but It seems your env has some issues with openmp... $\endgroup$
    – Aditya
    Jul 5, 2018 at 2:34

The best solution I found was here.

Check your anaconda/lib folder, ll lib*omp*, do you see some old libiomp5.dylib file? Remove it.

On mac, you can get the latest libomp by running brew install libomp.

  • $\begingroup$ cd ~/opt/anaconda3/lib and ls libio* to find these archives $\endgroup$
    – igorkf
    Aug 5, 2021 at 17:58

Check if you have 'Inf' values in the data. This is often the case when using pct_change(). xgBoost crashes the kernel when using Inf values.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.