Python 英特尔 MKL 致命错误:无法加载 libmkl_avx2.so 或 libmkl_def.so
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36659453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so
提问by Chris Parry
I am running a python script and I get this error:
我正在运行 python 脚本,但出现此错误:
Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so.
Both files are present in the anaconda2/lib directory. How can I fix this error? Thanks.
这两个文件都存在于 anaconda2/lib 目录中。我该如何解决这个错误?谢谢。
回答by Zaikun Xu
If you use conda, try with these two commands:
如果您使用 conda,请尝试使用以下两个命令:
conda install nomkl numpy scipy scikit-learn numexpr
conda remove mkl mkl-service
It should fix your problem.
它应该可以解决您的问题。
回答by Drew Swartz
I ran into this problem after installing anaconda3 (vesion 4.2.0). The fix for me was simple, and I was able to keep using mkl. Just update to the latest numpy version.
安装anaconda3(版本4.2.0)后我遇到了这个问题。对我来说修复很简单,我能够继续使用 mkl。只需更新到最新的 numpy 版本。
conda update numpy
回答by yanir
Just wanted to note that Anaconda 4.0.0, shipped with mkl enabled by default, has this issue. The problem is indeed with Anaconda, as it can be reproduced with the simple python test below.
只是想指出,默认情况下启用 mkl 的 Anaconda 4.0.0 存在此问题。问题确实出在 Anaconda 上,因为它可以通过下面的简单 python 测试重现。
The actual issue is that Anaconda linked with mkl, but not with libmkl_core.so, thus it has a missing symbol, and can be seen by running:
实际问题是 Anaconda 与 mkl 链接,但未与 libmkl_core.so 链接,因此它缺少符号,可以通过运行看到:
$ LD_DEBUG=symbols python -c 'import sklearn.linear_model.tests.test_randomized_l1' 2>&1 | grep -i error
2200: /opt/anaconda/lib/python2.7/site-packages/scipy/special/../../../../libmkl_avx.so: error: symbol lookup error: undefined symbol: mkl_dft_fft_fix_twiddle_table_32f (fatal)
I didn't want to uninstall mkl, as I'd like to have the performance boost, so I found a workaround which worked for me - preload libmkl_core.so before execution.
我不想卸载 mkl,因为我想提高性能,所以我找到了一个对我有用的解决方法 - 在执行之前预加载 libmkl_core.so。
$ python -c 'import sklearn.linear_model.tests.test_randomized_l1'
Intel MKL FATAL ERROR: Cannot load libmkl_avx.so or libmkl_def.so.
$
$ LD_PRELOAD=/opt/anaconda/lib/libmkl_core.so python -c 'import sklearn.linear_model.tests.test_randomized_l1'
$
回答by Masud
Got the same problem and solved by using the command:
遇到同样的问题并使用以下命令解决:
conda install nomkl
conda install nomkl
I got the solution from this discussion https://github.com/BVLC/caffe/issues/3884
我从这个讨论中得到了解决方案https://github.com/BVLC/caffe/issues/3884
回答by Pavel Komarov
I had this same issue using scikit-learn 0.19 and numpy 1.13.3 when running MLPRegressor (and also with a package called pyearth running an algorithm called MARS). I believe the root of the problem was that our python is part of an Anaconda install, but scikit-learn and numpy were installed via pip, and their expectations for mkl must not agree.
我在运行 MLPRegressor 时使用 scikit-learn 0.19 和 numpy 1.13.3 遇到了同样的问题(还有一个叫做 pyearth 的包运行一个叫做 MARS 的算法)。我认为问题的根源在于我们的 python 是 Anaconda 安装的一部分,但是 scikit-learn 和 numpy 是通过 pip 安装的,并且他们对 mkl 的期望必须不一致。
Unfortunately my framework is managed by some dedicated company admins, not by me, so I haven't gotten my guy to try recompiling numpy yet. But I was able to find a workaround based on this thread: Adding export LD_PRELOAD=/path/to/anaconda/lib/libmkl_def.so:/path/to/anaconda/lib/libmkl_avx.so:/path/to/anaconda/lib/libmkl_core.so:/path/to/anaconda/lib/libmkl_intel_lp64.so:/path/to/anaconda/lib/libmkl_intel_thread.so:/path/to/anaconda/lib/libiomp5.so
to my ~/.bashrc
causes the problem to disappear. It's super hacky, and I'd be lying if I said I knew exactly what it's doing (but this is helpful), so I'm hoping a recompile of numpy is a cleaner fix. But at least it works.
不幸的是,我的框架由一些专门的公司管理员管理,而不是由我管理,所以我还没有让我的人尝试重新编译 numpy。但是我能够找到基于此线程的解决方法:添加export LD_PRELOAD=/path/to/anaconda/lib/libmkl_def.so:/path/to/anaconda/lib/libmkl_avx.so:/path/to/anaconda/lib/libmkl_core.so:/path/to/anaconda/lib/libmkl_intel_lp64.so:/path/to/anaconda/lib/libmkl_intel_thread.so:/path/to/anaconda/lib/libiomp5.so
到我的~/.bashrc
原因导致问题消失。这是超级hacky,如果我说我确切地知道它在做什么(但这很有帮助),我会撒谎,所以我希望重新编译numpy是一个更清晰的修复。但至少它有效。
Note it is better performance-wise to have the versions of these packages that use mkl. Installing the nomkl versions is a workaround but not a true solution.
请注意,使用 mkl 的这些软件包的版本在性能方面会更好。安装 nomkl 版本是一种解决方法,但不是真正的解决方案。
回答by KamKam
In case anyone has a similarissue and gets errors that libmkl_p4m.so or libmkl_p4.socannot be found (this occurred for me when calling certain numpy functions), I tried reinstalling / updating different python modules and reverting / updating to various versions of Anaconda, and neither worked. However I found that completely uninstalling anaconda and re-installing it (to version 4.4.10) solved the issue.
如果有人遇到类似问题并收到找不到 libmkl_p4m.so 或 libmkl_p4.so 的错误(这对我来说是在调用某些 numpy 函数时发生的),我尝试重新安装/更新不同的 python 模块并恢复/更新到各种版本的 Anaconda ,而且都没有奏效。但是我发现完全卸载 anaconda 并重新安装它(到版本 4.4.10)解决了这个问题。
回答by libphy
Wanted to add on Valilutzik and Zaikun Xu's thread. I can't add comments since I don't have enough points yet.conda install nomkl numpy scipy scikit-learn numexpr
worked for me without having to remove mkl and mkl-service.
想补充一下 Valilutzik 和 Zaikun Xu 的帖子。由于我的积分还不够,我无法添加评论。conda install nomkl numpy scipy scikit-learn numexpr
为我工作而不必删除 mkl 和 mkl-service。
Adding an answer to Lee's question if nomkl
will be slower:
mkl is a Intel math kernel library and is hand-optimized for intel cpus. nomkl uses OpenBlas according to this: https://docs.continuum.io/mkl-optimizations/It seems that mkl is quite faster on many matrix operations for intel cpus (see https://software.intel.com/en-us/articles/performance-comparison-of-openblas-and-intel-math-kernel-library-in-r)
I've seen someone saying nomkl is faster for AMD cpus (maybe because mkl doesn't work correctly in AMD?)
为 Lee 的问题添加一个答案是否nomkl
会更慢:mkl 是一个英特尔数学内核库,并且针对英特尔 CPU 进行了手动优化。nomkl 根据以下内容使用 OpenBlas:https://docs.continuum.io/mkl-optimizations/ 似乎 mkl 在英特尔 cpus 的许多矩阵运算上速度相当快(请参阅https://software.intel.com/en-us /articles/performance-comparison-of-openblas-and-intel-math-kernel-library-in-r)
我看到有人说 nomkl 对于 AMD cpus 更快(可能是因为 mkl 在 AMD 中无法正常工作?)
回答by Klipiklop
All the solutions provided above did not work for me, but I found a good compromise:
上面提供的所有解决方案都不适合我,但我找到了一个很好的折衷方案:
for someone who has the same error and want's to keep Anaconda on his computer, and steel use mkl for (numpy and scipy) good process performance, the solution I propose:
对于有相同错误并希望将 Anaconda 保留在他的计算机上并且钢铁使用 mkl 以获得(numpy 和 scipy)良好流程性能的人,我提出的解决方案:
Edit your .bashrc
file.
编辑您的.bashrc
文件。
Look for something like export PATH="/home/anaconda2/bin:$PATH"
in the file.
export PATH="/home/anaconda2/bin:$PATH"
在文件中查找类似的内容。
Put a #
at the beginning to comment it from the script:
#export PATH="/home/anaconda2/bin:$PATH"
将 a#
放在开头以从脚本中对其进行注释:
#export PATH="/home/anaconda2/bin:$PATH"
Open a new terminal and you should be running the base python installation.
打开一个新终端,您应该正在运行基本的 python 安装。
It worked for me, hope it will be helpfull.
它对我有用,希望它会有所帮助。
回答by Armughan Shahid
The following worked for me
以下对我有用
conda install -f numpy
回答by user3098840
None of the above answers worked for me. In my case, @Nehal J Wani
's comment below the OP's question led to the solution: As stated in the linked Intel support document, a single dynamic library can be used to link to the MKL.
以上答案都不适合我。就我而言,@Nehal J Wani
在 OP 问题下方的评论导致了解决方案:如链接的英特尔支持文档中所述,可以使用单个动态库链接到 MKL。
After editing my project's Makefile to replace the following libraries
-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core
with
-lmkl_rt
and re-building, the error disappeared.
编辑我的项目的Makefile文件替换下列库之后
-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core
与
-lmkl_rt
重楼和,错误消失。