问题场景:
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/.
解决方法:
import os os.environ['KMP_DUPLICATE_LIB_OK']='TRUE'
上面方法最简单但是缺点是每个代码文件(只和相关模块导致这个错误的)必须加个,有点闹心
还有个解决办法:根据python interpreter的路径,删除其目录下多余的libiomp5md.dll
(记得备份文件和存储路径),不然可能会造成其他未知的问题。找到某个env(例如py38)下删除了第二个或者第三个都可以解决,第二个在C:\Users\Administrator\anaconda3\envs\py38\Lib\site-packages\torch\lib下的libiomp5md.dll文件;第三个在C:\Users\Administrator\anaconda3\envs\py38\Library\bin下的libiomp5md.dll文件
第一个libiomp5md.dll位置是在C:\Users\Administrator\anaconda3\envs\py38\Lib\site-packages\paddle\libs
第二个libiomp5md.dll位置是在C:\Users\Administrator\anaconda3\envs\py38\Lib\site-packages\torch\lib
第三个libiomp5md.dll位置是在C:\Users\Administrator\anaconda3\envs\py38\Library\bin
第二个libiomp5md.dll和第三个libiomp5md.dll二选一删除一个就行,接着运行代码就不会报错了