错误 # 15: 初始化 libiop5.dylib,但发现 libiop5.dylib 已经初始化

使用 matplotlib 时获取错误消息:

错误 # 15: 初始化 libiop5.dylib,但发现 libiop5.dylib 已经初始化了 提示: 这意味着 OpenMP 运行时的多个副本已经链接到程序中。那很危险,因为它可以 降低性能或导致不正确的结果。最好的做法 是确保只有一个 OpenMP 运行时链接到 过程,例如避免 OpenMP 运行时的静态链接 作为一个不安全、不受支持、没有文档的解决方案,您可以 将环境变量设置为 kMP _ DUPLICATE _ LIB _ OK = TRUE,以允许 程序继续执行,但这可能导致崩溃或静默 产生不正确的结果。有关更多信息,请参阅 Http://www.intel.com/software/products/support/.

58714 次浏览

Do the following to solve the issue:

import os


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

Answer found at: https://github.com/dmlc/xgboost/issues/1715

Be aware of potential side-effects:

but that may cause crashes or silently produce incorrect results.

This is a better solution, if applicable. Else, anyway gcamargo’s solution is likely to work. However, it comes with a warning "that it may cause crashes or silently produce incorrect results"

I had the same error on my Mac with a python program using numpy, keras, and matplotlib. I solved it with

conda install nomkl

Answer found at: https://github.com/dmlc/xgboost/issues/1715

So, for those of you getting this same issue with lightgbm, I found in the documentation that you can

  1. pip uninstall lightgbm
  2. pip install lightgbm
  3. Run the following in anaconda environmnet (if you're running Conda)
ln -sf `ls -d "$(brew --cellar libomp)"/*/lib`/* $CONDA_PREFIX/lib

These three things worked for me.

Had same issue in OSX when updating tensoflow to 1.13 using conda.

  • Solution 1: /gcamargo worked but 3x slower per training epoch.
  • Solution 2: /sjcoding worked and removed serious warining but also 3x slower in training.
  • Solution 3: that restored performance was: Install pip in new conda env and use pip to install tensorflow. Using conda-forge also worked but version of tf is old.

Apparently the new Intel-MKL optimizations in Anaconda are broken for OSX tensorflow.

I had the same issue in a conda environment where TensorFlow was installed. After doing

  • pip uninstall tensorflow
  • pip install tensorflow

the problem was gone.

Try to change the backend of matplotlib.

For example, Tkagg backend causes this problem in my case. I changed it to Qt5Agg

matplotlib.use('Qt5Agg')

and it helps.

I had the same issue on macOS and found the following reasons:

Problem:

I had a conda environment where Numpy, SciPy and TensorFlow were installed.

Conda is using Intel(R) MKL Optimizations, see docs:

Anaconda has packaged MKL-powered binary versions of some of the most popular numerical/scientific Python libraries into MKL Optimizations for improved performance.

The Intel MKL functions (e.g. FFT, LAPACK, BLAS) are threaded with the OpenMP technology.

But on macOS you do not need MKL, because the Accelerate Framework comes with its own optimization algorithms and already uses OpenMP. That is the reason for the error message: OMP Error #15: ...

Workaround:

You should install all packages without MKL support:

conda install nomkl

and then use

conda install numpy scipy pandas tensorflow

followed by

conda remove mkl mkl-service

For more information see conda MKL Optimizations.

Check if there's an update for the mkl package in your env (anaconda).

I was able to solve my case simply by updating mkl.

conda install -c intel mkl

(macOS Catalina 10.15.5)

conda install --revision 0 doesn't solve UnsatisfiableError: The following specifications... for me. So I manually install nomkl and remove mkl and mil-service in Anaconda-Navigator environment, and it works great for me!

Confronted with the same error #15, none of the solutions to-date (5 Feb 2021) fully worked despite being helpful. However, I did manage to solve it while avoiding: dithering with dylib libraries, installing from source, or setting the environment variable KMP_DUPLICATE_LIB_OK=TRUE and its downsides of being an “unsafe, unsupported, undocumented workaround” and its potential “crashes or silently produce incorrect results”.

The trouble was that conda wasn’t picking up the non-mkl builds of tensorflow (v2.0.0) despite loading the nomkl package. What finally made this solution work was to:

  • ensure I was loading packages from the defaults channel (ie. from a channel with a non-mkl version of tensorflow. As of 5 Feb 2021, conda-forge does not have a tensorflow version of 2.0 or greater).
  • specify the precise build of the tensorflow version I wanted: tensorflow>=2.*=eigen_py37h153756e_0. Without this, conda kept loading the mkl_... version of the package despite the nomkl package also being loaded.

I created a conda environment using the following environment.yml file (as per the conda documentation for managing environments) :

name: tf_nomkl
channels:
- conda-forge
- defaults
dependencies:
- nomkl
- python>=3.7
- numpy
- scipy
- pandas
- jupyter
- jupyterlab
- nb_conda
- nb_conda_kernels
- ipykernel
- pathlib
- matplotlib
- seaborn
- tensorflow>=2.*=eigen_py37h153756e_0

You could try to do the same without an environment.yml file, but it’s better to load all the packages you want in an environment in one go if you can. This solution works on MacOS Big Sur v11.1.

I was getting the same error as mentioned in the original question when I ran a code with Tensorflow on my macOS Monterey. I tried installing nomkl and removing mkl as suggested in many of the previous answers. However this gave me trouble on running readcsv module of pandas and many other modules from different packages. A friend told me that newer versions of macOS have trouble with the usual Tensorflow and therefore pypi has launched a special version of TF called tf-nightly.

https://pypi.org/project/tf-nightly/#description

This installation solved the problem for me.

I had the same problem. Nothing you suggested solved the issue. I found that a possible cause is that you have multiple OpenMP libraries installed on your machine and they conflict with each other. Plus, I found that the problem was numpy and I did the upgrade (conda update numpy) and FINALLY IT WORKED!!!

I am using Macbook M1 and I faced the same issue. I solved this problem after removing the mkl package from my conda environment using the following command:

conda remove mkl

This issue happens because mkl is developed for Intel users and many of my packages were comming from mkl. After you remove this package, you will be required to reinstall many packages that you use through mkl. Also, in my case, when I tried to install pandas afterwards, there was a dependency issue. I solved this issue as well after updating all conda packages using the following command:

conda update --all

A useful link that helped me figure this out:

For me, this problem came up when I imported pytorch after numpy. Importing them in this order fixed my problem:

import torch
import numpy as np