本文最后更新于:2023年12月5日 下午

在python调用matplotlib时有时会报错 OMP Error 15 Initializing libiomp5md.dll, but found libiomp5md.dll already initialized,本文记录解决方案。

错误复现

  • 报错信息:OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized
1
2
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.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/.

问题原因

  • 可能是从不同位置加载了 libiomp5md.dll 库,触发了某种自检,报出了错误

解决方案

方案1

  • 忽略该错误,在环境变量中加入 KMP_DUPLICATE_LIB_OK 设置为 True
1
2
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"

通常 libiomp5md.dll 库没有特殊的变化,从不同位置加载其行为也是相同的,是大家广泛采取的解决方案

方案2

  • 在运行的python环境中搜索 libiomp5md.dll 文件,删除多余的文件,仅保留 torch 中的库可以避免这个错误
  • 不过可能会造成其他未知的问题(我就是在删除之后 matplotlib 再也打不出图像了)
  • 删除文件需要谨慎

参考资料



文章链接:
https://www.zywvvd.com/notes/coding/python/omp-error-15/omp-error-15/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

OMP Error 15 Initializing libiomp5md.dll, but found libiomp5md.dll already initialized 解决方案
https://www.zywvvd.com/notes/coding/python/omp-error-15/omp-error-15/
作者
Yiwei Zhang
发布于
2021年7月23日
许可协议