sklearn OMP: Error #15 when fitting models

ADJ picture ADJ · Dec 12, 2013 · Viewed 11.7k times · Source

I have recently uninstalled a nicely working copy of Enthought Canopy 32-bit and installed Canopy version 1.1.0 (64 bit). When I try to use sklearn to fit a model my kernel crashes, and I get the following error:

The kernel (user Python environment) has terminated with error code 3. This may be due to a bug in your code or in the kernel itself.

Output captured from the kernel process is shown below.

OMP: Error #15: Initializing libiomp5md.dll, but found mk2iomp5md.dll 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://www.intel.com/software/products/support/.

The same code was running just fine under Canopy's 32 bit. The code is really just a simple fit of a linear_model.SGDClassifier(loss='log') (same error for Logistic Regression, haven't tried other models)

How do I fix this?

Answer

user4720834 picture user4720834 · Apr 9, 2015

I had the same problem, coming from conflicting installations in numpy and from canopy. Resolved it by writing:

import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"

Not an elegant solution, but it did the job for me.