Dlib: ImportError: libmkl_rt.so: cannot open shared object file

Created on 12 May 2017  Â·  15Comments  Â·  Source: davisking/dlib

I have installed dlib using pip install dlib but, upon using the correlation_tracker() I am getting the following error when I'm executing my program -

Traceback (most recent call last): File "tracking.py", line 9, in <module> import dlib File "/usr/local/lib/python2.7/dist-packages/dlib/__init__.py", line 1, in <module> from .dlib import * ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory

I can see that libmkl_rt.so is in the folder /opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/lib/ia32_lin/libmkl_rt.so but, somehow maybe its not linked. Can anyone please help me to solve this?

Most helpful comment

pip install mkl
it works to me

All 15 comments

You have to tell your OS about the MKL. So set your LD_LIBRARY_PATH or whatever equivalent environment variable your OS uses.

missionary0, did you happen to solve this issue? i am facing the same problem while importing dlib.
I installed dlib using PIP and later one more time from source.

import dlib
Traceback (most recent call last):
File "", line 1, in
File "/home/jarvis/.virtualenvs/cv2/local/lib/python2.7/site-packages/dlib-19.4.99-py2.7-linux-x86_64.egg/dlib/__init__.py", line 1, in
from .dlib import *
ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory

Yeah! It can be solved as follows -
Create a file such as mylibs.conf in /etc/ld.so.conf.d. Then just add the path to the directory in which libmkl_rt.so is located in your system. It will probably be located in the following 3 directories -

  1. /opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/lib/ia32_lin/
  2. /opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/lib/intel64_lin/
  3. /opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/lib/intel64_lin_mic/

Or maybe, you can just find it using locate libmkl_rt.so. Then write to the file and run sudo ldconfig. This will create links to those libraries and then the OS would be able to locate them when needed.

Hi - Absolute noob question ..

Error as seen below :-

(opencv_venv) dhankar@dhankar-VPCEB44EN:~$ python
Python 3.5.2 (default, Aug 18 2017, 17:48:00) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dhankar/.virtualenvs/opencv_venv/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
    from .dlib import *
ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory
>>> 
>>> 

Located - libmkl_rt.so

(opencv_venv) dhankar@dhankar-VPCEB44EN:~$ locate libmkl_rt.so
/home/dhankar/anaconda2/lib/libmkl_rt.so
/home/dhankar/anaconda2/pkgs/mkl-11.3.3-0/lib/libmkl_rt.so

1- Tried Copying file into - venv as below --- no success.

~$ sudo cp -b /home/dhankar/anaconda2/lib/libmkl_rt.so /home/dhankar/.virtualenvs/opencv_venv/lib/python3.5/site-packages

2- Tried Sym LINK -- no sucess

:~/.virtualenvs/opencv_venv/lib/python3.5/site-packages$ ln -s /home/dhankar/anaconda2/lib/libmkl_rt.so libmkl_rt.so

Am not sure which package needs to be installed to make available - libmkl_rt.so , for a import within - dlib ?

3- Further tried ---

(opencv_venv) dhankar@dhankar-VPCEB44EN:~$ sudo apt-get install libmkl_rt.so
(opencv_venv) dhankar@dhankar-VPCEB44EN:~$ sudo apt-get install mkl-11.3.3-0
(opencv_venv) dhankar@dhankar-VPCEB44EN:~$ sudo apt-get install mkl
(opencv_venv) dhankar@dhankar-VPCEB44EN:~$ sudo ldconfig


Obviously nothing ... kindly someone guide me -
Further update ---

$ cd /etc/ld.so.conf.d
:/etc/ld.so.conf.d$ ls
fakeroot-x86_64-linux-gnu.conf  i386-linux-gnu_GL.conf  x86_64-linux-gnu.conf      x86_64-linux-gnu_GL.conf
i386-linux-gnu.conf             libc.conf               x86_64-linux-gnu_EGL.conf

$ sudo touch dhankar_extra_libs.conf
[sudo] password for dhankar: 
# Content of File --- dhankar_extra_libs.conf
# My Extra Libs FIle Paths 

/home/dhankar/anaconda2/lib/libmkl_rt.so
/home/dhankar/anaconda2/pkgs/mkl-11.3.3-0/lib/libmkl_rt.so
#
:/etc/ld.so.conf.d$ ls
dhankar_extra_libs.conf         i386-linux-gnu.conf     libc.conf              x86_64-linux-gnu_EGL.conf
fakeroot-x86_64-linux-gnu.conf  i386-linux-gnu_GL.conf  x86_64-linux-gnu.conf  x86_64-linux-gnu_GL.conf
$ source dhankar_extra_libs.conf
Segmentation fault (core dumped)
Segmentation fault (core dumped)
$ sudo gedit libc.conf

# libc default configuration
# /usr/local/lib

$ cd /usr/local/lib
:/usr/local/lib$ sudo ln -s /home/dhankar/anaconda2/lib/libmkl_rt.so libmkl_rt.so

Still no success :)

Run ldconfig after you update /etc/ld.so.conf.d

Created a Conda Env , dlib_opencv

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ pip freeze
certifi==2016.2.28
cycler==0.10.0
decorator==4.1.2
dlib==19.7.0
matplotlib==2.0.2
networkx==2.0
numpy==1.13.1
olefile==0.44
Pillow==4.2.1
pyparsing==2.2.0
python-dateutil==2.6.1
pytz==2017.2
PyWavelets==0.5.2
scikit-image==0.13.0
scipy==0.19.1
six==1.11.0

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ python
Python 3.5.4 |Continuum Analytics, Inc.| (default, Aug 14 2017, 13:26:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
    from .dlib import *
ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory
>>> 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ locate libmkl_rt.so
/home/dhankar/anaconda2/lib/libmkl_rt.so
/home/dhankar/anaconda2/pkgs/mkl-11.3.3-0/lib/libmkl_rt.so

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ cd /home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ ls
certifi                           matplotlib-2.0.2-py3.5-nspkg.pth  pip-9.0.1-py3.5.egg-info         scikit_image-0.13.0.dist-info
certifi-2016.2.28-py3.5.egg-info  mpl_toolkits                      pkg_resources                    scipy
cycler-0.10.0.dist-info           networkx                          __pycache__                      scipy-0.19.1.dist-info
cycler.py                         networkx-2.0.dist-info            pylab.py                         setuptools
dateutil                          numpy                             pyparsing-2.2.0.dist-info        setuptools-36.4.0-py3.5.egg-info
decorator-4.1.2.dist-info         numpy-1.13.1.dist-info            pyparsing.py                     six-1.11.0.dist-info
decorator.py                      olefile                           python_dateutil-2.6.1.dist-info  six.py
dlib                              olefile-0.44.dist-info            pytz                             skimage
dlib-19.7.0.dist-info             OleFileIO_PL.py                   pytz-2017.2.dist-info            wheel
easy_install.py                   PIL                               PyWavelets-0.5.2.dist-info       wheel-0.29.0-py3.5.egg-info
matplotlib                        Pillow-4.2.1.dist-info            pywt
matplotlib-2.0.2.dist-info        pip                               README

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ cd dlib
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages/dlib$ ls
dlib.so  examples  __init__.py  __pycache__

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages/dlib$ ln -s /home/dhankar/anaconda2/lib/libmkl_rt.so libmkl_rt.so

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages/dlib$ cd ..

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ ln -s /home/dhankar/anaconda2/lib/libmkl_rt.so libmkl_rt.so

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ cd ~
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ python
Python 3.5.4 |Continuum Analytics, Inc.| (default, Aug 14 2017, 13:26:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
    from .dlib import *
ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory
>>> 


(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ cd /home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ sudo cp -b /home/dhankar/anaconda2/lib/libmkl_rt.so /home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages
[sudo] password for dhankar: 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ ls
certifi                           matplotlib                        Pillow-4.2.1.dist-info           pywt
certifi-2016.2.28-py3.5.egg-info  matplotlib-2.0.2.dist-info        pip                              README
cycler-0.10.0.dist-info           matplotlib-2.0.2-py3.5-nspkg.pth  pip-9.0.1-py3.5.egg-info         scikit_image-0.13.0.dist-info
cycler.py                         mpl_toolkits                      pkg_resources                    scipy
dateutil                          networkx                          __pycache__                      scipy-0.19.1.dist-info
decorator-4.1.2.dist-info         networkx-2.0.dist-info            pylab.py                         setuptools
decorator.py                      numpy                             pyparsing-2.2.0.dist-info        setuptools-36.4.0-py3.5.egg-info
dlib                              numpy-1.13.1.dist-info            pyparsing.py                     six-1.11.0.dist-info
dlib-19.7.0.dist-info             olefile                           python_dateutil-2.6.1.dist-info  six.py
easy_install.py                   olefile-0.44.dist-info            pytz                             skimage
libmkl_rt.so                      OleFileIO_PL.py                   pytz-2017.2.dist-info            wheel
libmkl_rt.so~                     PIL                               PyWavelets-0.5.2.dist-info       wheel-0.29.0-py3.5.egg-info

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ cd ~
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ python
Python 3.5.4 |Continuum Analytics, Inc.| (default, Aug 14 2017, 13:26:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
    from .dlib import *
ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory
>>> 

(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ cd /home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ ln -s /home/dhankar/anaconda2/lib/libmkl_rt.so libmkl_rt.so
ln: failed to create symbolic link 'libmkl_rt.so': File exists
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ sudo rm -f libmkl_rt.so
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ ln -s /home/dhankar/anaconda2/lib/libmkl_rt.so libmkl_rt.so
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages$ cd ~
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ python
Python 3.5.4 |Continuum Analytics, Inc.| (default, Aug 14 2017, 13:26:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
    from .dlib import *
ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory
>>> 
>>> 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ cd /etc/ld.so.conf.d
(dlib_opencv) dhankar@dhankar-VPCEB44EN:/etc/ld.so.conf.d$ ls
dhankar_extra_libs.conf         i386-linux-gnu.conf     libc.conf              x86_64-linux-gnu_EGL.conf
fakeroot-x86_64-linux-gnu.conf  i386-linux-gnu_GL.conf  x86_64-linux-gnu.conf  x86_64-linux-gnu_GL.conf
(dlib_opencv) dhankar@dhankar-VPCEB44EN:/etc/ld.so.conf.d$ sudo gedit dhankar_extra_libs.conf

(gedit:10503): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files

** (gedit:10503): WARNING **: Set document metadata failed: Setting attribute metadata::gedit-spell-enabled not supported

** (gedit:10503): WARNING **: Set document metadata failed: Setting attribute metadata::gedit-encoding not supported

** (gedit:10503): WARNING **: Set document metadata failed: Setting attribute metadata::gedit-spell-enabled not supported

** (gedit:10503): WARNING **: Set document metadata failed: Setting attribute metadata::gedit-encoding not supported

** (gedit:10503): WARNING **: Set document metadata failed: Setting attribute metadata::gedit-position not supported
(dlib_opencv) dhankar@dhankar-VPCEB44EN:/etc/ld.so.conf.d$ sudo ldconfig
(dlib_opencv) dhankar@dhankar-VPCEB44EN:/etc/ld.so.conf.d$ cd ~
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ python
Python 3.5.4 |Continuum Analytics, Inc.| (default, Aug 14 2017, 13:26:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dhankar/anaconda2/envs/dlib_opencv/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
    from .dlib import *
ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory
>>> 
>>> 
(dlib_opencv) dhankar@dhankar-VPCEB44EN:~$ 


I will soon edit this comment and make it shorter , in the meanwhile - kindly bear with me and suggest if there is a solution - thanks

Regards
Rohit

This isn't a dlib problem.

Google "how to add to ldconfig path"

@davisking - you sir are truly a KING - many thanks my issue is resolved :)
God Speed - dlib is installed n running.

@RohitDhankar I had the same issue as you did. How did you resolve yours?

@iakash-1326 - update your ~./bashrc with the -- libmkl_rt.so , path.
No need to make any changes to --- cd /etc/ld.so.conf.d

### DLIB 

# LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib

# MKL
export LD_LIBRARY_PATH=/home/dhankar/anaconda2/pkgs/mkl-11.3.3-0/lib/:$LD_LIBRARY_PATH

I didnt make any changes within - cd /etc/ld.so.conf.d
Kindly note export LD_LIBRARY_PATH is as suggested by @davisking , in his very first answer above . My bad i should have read his instructions properly .

@RohitDhankar @davisking thank you so much. You guys literally saved my semester.
This is what I got on running locate libmkl_rt.so

akash1326@theodrew:~$ locate libmkl_rt.so /home/akash1326/anaconda3/lib/libmkl_rt.so /home/akash1326/anaconda3/pkgs/mkl-11.3.1-0/lib/libmkl_rt.so /home/akash1326/anaconda3/pkgs/mkl-2017.0.1-0/lib/libmkl_rt.so /home/akash1326/anaconda3/pkgs/mkl-2017.0.3-0/lib/libmkl_rt.so

so, this is the change I made to ./bashrc as you suggested

export LD_LIBRARY_PATH=/usr/local/lib export LD_LIBRARY_PATH=/home/akash1326/anaconda3/lib/:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=/home/akash1326/anaconda3/pkgs/mkl-11.3.1-0/lib/:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=/home/akash1326/anaconda3/pkgs/mkl-2017.0.1-0/lib/:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=/home/akash1326/anaconda3/pkgs/mkl-2017.0.3-0/lib/:$LD_LIBRARY_PATH

its working well now

pip install mkl
it works to me

I have also had the following traceback

ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory

with python 3.6.6 and dlib 19.15.0 on Ubuntu 16.04.4 LTS, but unlike the previous commentators, my command locate libmkl_rt.so returned nothing. I tried everything described above, but it did not help me.
After all I solved the problem by removing dlib from pip and building it from source.

@RohitDhankar @iakash2604 Thanks
This is what I got on running locate libmkl_rt.so

/home/sager/anaconda3/envs/tf/lib/libmkl_rt.so
/home/sager/anaconda3/lib/libmkl_rt.so
/home/sager/anaconda3/pkgs/mkl-2018.0.2-1/lib/libmkl_rt.so
/home/sager/anaconda3/pkgs/mkl-2018.0.3-1/lib/libmkl_rt.so
/home/sager/anaconda3/pkgs/mkl-2019.1-144/lib/libmkl_rt.so
this is the change I made to ~/.bashrc as you suggested:
_# LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib

MKL

export LD_LIBRARY_PATH=/home/sager/anaconda3/envs/tf/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sager/anaconda3/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sager/anaconda3/pkgs/mkl-2018.0.2-1/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sager/anaconda3/pkgs/mkl-2018.0.3-1/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sager/anaconda3/pkgs/mkl-2019.1-144/lib/:$LD_LIBRARY_PATH_

I should run in env It works well.

(fs35) sager@cumt:~$ python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import dlib

I've just had the same problem. I tried Laviyy's suggestion above (pip install mkl) and it solved the problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rsadiq picture rsadiq  Â·  4Comments

pliablepixels picture pliablepixels  Â·  4Comments

srikanthreddybethi picture srikanthreddybethi  Â·  4Comments

AeroClassics picture AeroClassics  Â·  4Comments

maromcik picture maromcik  Â·  4Comments