解决OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized问题

本来几条想画几个激活函数的图像

import matplotlib.pyplot as plt
import torch

x = torch.linspace(-10, 10, 100)
z = x.sigmoid()
plt.subplot(1, 2, 1), plt.plot(x), plt.title('Normal')
plt.subplot(1, 2, 2), plt.plot(z), plt.title('sigmoid')
plt.show()

结果运行代码的时候显示报错,提示

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

翻译出来是

OMP:错误#15:正在初始化libiomp5md.dll,但发现libiomp5md.dll已经初始化。
OMP:这意味着OpenMP运行时的多个副本已链接到程序中。这很危险,因为它会降低性能或导致不正确的结果。最好的做法是确保只有一个OpenMP运行时被链接到进程中,例如,避免在任何库中静态链接OpenMP运行时。作为一种不安全、不受支持、没有文档记录的解决方法,您可以将环境变量KMP_DUPLICATE_LIB_OK=TRUE设置为允许程序继续执行,但这可能会导致崩溃或默默地产生不正确的结果。欲了解更多信息,请访问http://www.intel.com/software/products/support/。

我的解决办法是在程序中加入两行代码

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

        代码解释:

        (1)第一行代码 import os 是在Python程序中导入操作系统模块(os)。这个模块提供了许多与操作系统交互的功能,例如读取和修改环境变量、列出目录中的文件等;

        (2)第二行代码 os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE" 是通过 os.environ 访问当前环境变量的字典,并设置其中的 "KMP_DUPLICATE_LIB_OK" 键的值为 "TRUE"。这个环境变量的作用是告诉系统在加载库文件时忽略重复的库文件;

        通俗的讲,就是当一个程序需要加载多个库文件时,如果其中存在同名库文件,系统会报错并停止加载。而这两行代码设置 "KMP_DUPLICATE_LIB_OK" 环境变量为 "TRUE" 后,系统会忽略这些重复的库文件,继续加载其他库文件。这对于某些特定情况下的程序运行是必要的。

       亲测有效, 希望这种方法可以帮助到大家。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

咸鱼翻身的路上

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

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

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

打赏作者

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

抵扣说明:

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

余额充值