如何解决OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.报错?

在运行faster whisper时报上面的错误,设置了os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"似乎可以解决,但是看到下面的提示,似乎这样做不太好,会影响程序的运行。

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

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

我相信网上能找到的大部分的解决方案都是这样的。

方式二:

方式一并不能从根本上解决问题,只是允许加载多个相同名称的dll而已,要想从根本上解决,我们可以找到多余的dll,然后删除掉。

比如:

删除D:\Software\office\python\Anaconda\envs\faster_whisper\Library\bin\libiomp5md.dll

上面中的faster_whisper是我创建的conda虚拟环境。你可以先使用conda env list命令查看你自己的conda虚拟环境,找到对应项目使用的环境,然后找到Library\bin\libiomp5md.dll,删除或移到其它路径。

参考文档

[1] 关于OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.错误解决方法

[2] sklearn OMP: Error #15 (“Initializing libiomp5md.dll, but found mk2iomp5md.dll already initialized.”) when fitting models

Q.E.D.


热爱生活,热爱程序