Lightgbm运行 OMP: Error #15: Initializing libomp.dylib, but found libiomp5.dylib already initialize

运行lightgbm 2.2.3时出现如下错误:
OMP: Error #15: Initializing libomp.dylib, but found libiomp5.dylib already initialize

下面有一段解释:
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/

意思是说:程序运行时有链接到多个openMP副本,这可能导致性能下降或出现不正确的结果,最好是确保只有一个被接入程序中。
可是根本不懂openMP是什么啊!〜〜〜

先解决此问题:

方法1)

如解释中所说,将环境变量 KMP_DUPLICATE_LIB_OK设为TRUE,但是这也有可能导致崩溃或者产生错误结果。。。

import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'

方法2)

在LightGBM的FAQ网页中的Question 10有提到这个问题,并给出了解决方案。(但只是针对macOS用户,其他用户则需自行找出冲突包并选择其中之一。)

If you are using Python distributed by Conda, then it is highly likely that the error is caused by the numpy package from Conda which includes the mkl package which in turn conflicts with the system-wide library. In this case you can update the numpy package in Conda or replace the Conda’s OpenMP library instance with system-wide one by creating a symlink to it in Conda environment folder $CONDA_PREFIX/lib.

如果Python是基本于Conda安装的,则Conda上的numpy包中的mkl很容易与系统内库发生冲突,可选择update numpy package in Conda或者设置为系统库。

Assuming you are using macOS with Homebrew, the command which overwrites OpenMP library files in the current active Conda environment with symlinks to the system-wide library ones installed by Homebrew:

ln -sf `ls -d "$(brew --cellar libomp)"/*/lib`/* $CONDA_PREFIX/lib

在安装有Homebrew用conda的macOS的机器上,可直接在终端输入如上内容就可将conda环境连接到用Homebrew安装的系统范围内的库了,其中CONDA_PREFIX是Conda的安装路径。

你可能感兴趣的:(fix,errors)