目录
一、问题描述
最近再Pycharm运行代码是遇到下面的报错:
具体报错内容粘贴出来如下:
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/.
上述报错翻译成中文:
提示 这意味着OpenMP运行时的多个副本已经被链接到程序中。这是很危险的,因为它可能会降低性能或者导致不正确的结果。最好的办法是确保只有一个OpenMP运行时被链接到程序中,例如,避免在任何库中静态链接OpenMP运行时。作为一个不安全的、不被支持的、没有记录的变通方法,你可以设置环境变量KMP_DUPLICATE_LIB_OK=TRUE来允许程序继续执行,但是这可能会导致崩溃或者默默地产生不正确的结果。欲了解更多信息,请参见http://www.intel.com/software/products/support/。
二、原因分析
从翻译结果看,报错的主要原因是OpenMP运行时的多个副本已经被链接到程序中,它可能会降低性能或者导致不正确的结果。
三、解决办法
在Pycharm代码中加入下面两句代码:
import os
os.environ['KMP_DUPLICATE_LIB_OK']='TRUE'
再次运行,没有报错:
并生成了图像: