如何将“MKL_THREADING_LAYER=GNU”设置为 Python 脚本的环境变量?

如何将“MKL_THREADING_LAYER=GNU”设置为 Python 脚本的环境变量?

当我运行py脚本时出现如下错误

RuntimeError: To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU"
              in your environement.

我搜索了原因,并在终端尝试

export MKL_THREADING_LAYER=GNU

再次运行,问题仍然存在。我想检查环境变量是否存在,所以我尝试了

$ env MKL_THREADING_LAYER=GNU
env: ‘MKL_THREADING_LAYER’: No such file or directory

这是否意味着我不了解环境或者什么?

回到最初bug的代码,问题是这样的:

File "/home/chen/anaconda2/envs/rllab3/lib/python3.5/site-packages/theano/configdefaults.py", line 1251, in check_mkl_openmp

该库的代码设计如下:

def check_mkl_openmp():
if not theano.config.blas.check_openmp:
    return
import os
if ('MKL_THREADING_LAYER' in os.environ and
        os.environ['MKL_THREADING_LAYER'] == 'GNU'):
    return
try:
    import mkl
    if '2018' in mkl.get_version_string():
        raise RuntimeError('To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environement.')
except ImportError:
    raise RuntimeError(""" Could not import 'mkl'.  Either install mkl-service with conda or set MKL_THREADING_LAYER=GNU in your environment for MKL 2018.
If you have MKL 2017 install and are not in a conda environment you can set the Theano flag blas.check_openmp to False.  Be warned that if you set this flag and don't set the appropriate environment or make sure you have the right version you *will* get wrong results.
""")

我如何设置这个环境变量并使原始代码工作?

答案1

我用了

conda install mkl=2017

并且成功了!

答案2

将此行添加到您的~/.bashrc文件中

export MKL_THREADING_LAYER=GNU

,然后重新打开您的终端,它将起作用

答案3

我遇到了同样的错误,只需在终端上逐个输入并执行这些命令即可解决该问题。

conda install theano
conda install keras

我认为该错误意味着没有安装 theano,无论如何,它有效。

答案4

要将 MKL 2018 与 Theano 结合使用,您必须"MKL_THREADING_LAYER=GNU"在环境中进行设置。此命令将解决您的问题

conda install mkl=2018

相关内容