【Python】OMP: Error: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.的解决方案

报错现象:

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

我的运行软件为pycharm,用的解释器为anaconda下创建的pytorcn虚拟环境。

解决方案

第一步:

   究其原因其实是,anaconda的环境下存在两个libiomp5md.dll文件。所以直接去虚拟环境的路径下搜索这个文件,可以看到在环境里有两个dll文件:

图片1

    其中第一个是torch路径下的,第二个是虚拟环境本身路径下的,转到第二个目录下把它剪切到其他路径下备份就好(最好把路径也备份一下)。
第一个的路径为:
D:\Users\Hasee\anaconda3\envs\pytorch\Lib\site-packages\torch\lib
第二个的路径为:
D:\Users\Hasee\anaconda3\envs\pytorch\Library\bin
    我经过第一步操作,问题任然没有解决。于是在此次基础上,进行了下面的操作,这步操作下来,问题就解决了。

第二步:

  在运行的程序代码中,加入下面代码:
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
我经过上面的两步操作后,成功解决了问题。

总结:

 上面两步,可以是独立的两种解决方案,也可以是互相铺垫的一种解决方案,总之,每个人的问题情况或多或少有点不一样,所以对于各种方法借鉴参考,结合自己的实际情况分析研究,就会找到解决自己问题的方案。
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lingchen1906

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值