Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.

学习pytroch官方lenet网络demo时,报错

以下为完整报错信息

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/.

在第二条报错其实可以看到两个解决方法:

第一种方法

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.

这种方法不支持,有可能导致不正确的结果,但是优点是简单,目前没有发现什么导致不正确的结果

具体方法是在程序前面加入两行代码

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

经过本人验证确实可以解决

第二种方法

Hint This means that multiple copies of the OpenMP runtime have been linked into the program.

其实报错原因主要是anaconda环境存在两个libiomp5md.dll

我们经过在虚拟环境路径搜索确实发现了两个libiomp5md.dll

Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized._第1张图片

报错其实也给了我们第二种解决方法

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.

可以剪切掉Lib\site_packages\torch\lib中的,为了保险,建议备份

最后也成功运行了

PS:剪切掉Library\bin中的不行,我也不知道原因

问题解决

你可能感兴趣的:(pytorch,anaconda,conda,pytorch)