How to set "MKL_THREADING_LAYER=GNU" as an environment variable for a python script?
Emily Wong
When I run a py script there is an error like this
RuntimeError: To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environement.I googled why and in the terminal tried
export MKL_THREADING_LAYER=GNUand run again, but the problem still exists. I wanted to check whether the environment variable exists or not, so I tried
$ env MKL_THREADING_LAYER=GNU
env: ‘MKL_THREADING_LAYER’: No such file or directoryDoes that mean I don't get the environment or what?
Back to the code of the original bug, the problem is this:
File "/home/chen/anaconda2/envs/rllab3/lib/python3.5/site-packages/theano/configdefaults.py", line 1251, in check_mkl_openmpThis is how the code of the library is designed:
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.
""")How can I set this environment variable and make the original code work?
14 Answers
I used
conda install mkl=2017and it worked!
Add this line to your ~/.bashrc file
export MKL_THREADING_LAYER=GNU
then re-open your terminal, it will work
1I had the same error, and resolved it simply by typing and executing these commands one by one on the terminal.
conda install theano
conda install kerasI think the error meant that there was no theano installed, anyway, it worked.
1To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environment.
This command would solve your problem
conda install mkl=2018