ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory - tensorflow

I am trying to use tensorflow-gpu on my system. I have re-installed it many times, it gives the error give below. But when I use tensorflow-cpu it works fine. I have cuda 8.0 toolkit installed and cudnn 5.1.
Traceback (most recent call last):
File "finetune.py", line 17, in <module>
import tensorflow as tf
File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 72, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 61, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

If changing your path variable does not work, running the following in your terminal is what usually solves this for me:
sudo ldconfig /usr/local/cuda/lib64
(sometimes cuda may need to be something like cuda-8.0, depending on your installation)

The problem is that you don't have environment variable CUDA_HOME set. If you think you have CUDA installed, then you need to make sure that the above environment variable is set prob=perly and contains address of the CUDA installation directory where all share libraries are located.
export CUDA_HOME=/CUDA/installation/path
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CUDA_HOME/lib64:$CUDA_HOME/extras/CUPTI/lib64"

sudo ldconfig /usr/local/cuda/lib64
Works for me.
Please refer this link for more information.
https://github.com/tensorflow/tensorflow/issues/5343

Related

Keras the specified module could not be found

I am getting this error on Keras.
ImportError: DLL load failed: The specified module could not be found while importing Keras
What I tried?
-initially "conda install -c conda-forge keras"
-then i also followed the tensorflow install instructions on tensorflow website
-I tried installing Microsoft Visual C++ that did not solve
-Also downloaded a msvcp140_1.dll file and pasted it in the sys32 and syswow64 of windows folder,did not help
-while importing the tensorflow it is reflecting the same problem
-OS-MSW-8.1
import keras
Error in callback <bound method AutoreloadMagics.post_execute_hook of <autoreload.AutoreloadMagics object at 0x0000006394266548>> (for post_execute):
Traceback (most recent call last):
File "C:\Users\admin\Anaconda3\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\admin\Anaconda3\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\admin\Anaconda3\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\admin\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\admin\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
As confirmed in comments, the OP was missing some of the Visual Studio redistributables. After installing appropriate (in terms of architecture) vc_redist from here everything worked fine.

Could not find 'cudart64_100.dll' while trying to install tensorflow

I am trying to install tensorflow.
I have installed Cuda10.0 and cudnn, but I still get this error:
Traceback (most recent call last):
File "D:\python\lib\site-packages\tensorflow\python\platform\self_check.py", line 75, in preload_check
ctypes.WinDLL(build_info.cudart_dll_name)
File "D:\python\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/Python_test/Python算法成品/机器学习/test/test.py", line 4, in <module>
import tensorflow as tf
File "D:\python\lib\site-packages\tensorflow\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "D:\python\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "D:\python\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
self_check.preload_check()
File "D:\python\lib\site-packages\tensorflow\python\platform\self_check.py", line 82, in preload_check
% (build_info.cudart_dll_name, build_info.cuda_version_number))
ImportError: Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 10.0 from this URL: `enter code here`https://developer.nvidia.com/cuda-90-download-archive
What am I missing or doing wrong?
To fix the issue, either: Install CUDA from September 2018, which comes with cudart64_100.dll and other 32 bit *100.dlls and 64 bit *100 libraries.
Or, if you want future support:
Install the latest NVIDIA GPU Computing Toolkit.
However, because the newest version of the CUDA library is cudart64_101.dll and TensorFlow 2.0 requires the older cudart64_100.dll, also install the CUDA from September 2018.
Then copy cudart64_100.dll library from the old install of CUDA to the new one.
Or just download the library from the file attached further below and copy it into your last CUDA installation directory in program files.
For more details please refer here

import tensorflow as tf gives errors even after installing without errors

I've been trying to solve this issue for long time. After many attempts in my existing python=3.5 env (in Anaconda), I deleted it and created a new env again just to properly install tensorflow with gpu support. To do that I did conda create -n FALL python=3.5 and then pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.11.0-cp35-cp35m-win_amd64.whl as suggested in tensorflow site, because I am on Windows 10 and have Anaconda. There was no error during installation. And I have been using Cuda 8.0 and cuDNN for my other deep learning practices without any hinders. So I could type python in my activated env. To check if tensorflow is installed accurately I did import tensorflow as tf and got
Traceback (most recent call last):
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\username\Anaconda3\envs\FALL\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\username\Anaconda3\envs\FALL\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\username\Anaconda3\envs\FALL\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\username\Anaconda3\envs\FALL\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
I would like someone could help me as possible.
Not sure if you are still looking for this question to be answered, but seeing as I just battled this very issue for the past few days, I figured I'd leave my two cents here in case it helps anyone moving forward.
As an initial note, I was not installing tensorflow through anaconda, but rather just via a pip install in a python virtualenv. I expect the solution to this issue would be similar using either anaconda or just pip.
It really just turned out in the end that I had one or more programs installed in incompatible versions for tensorflow.
As of my writing of this, tensorflow-gpu requires CUDA 9.0, CUPTI (should be included with the CUDA install), and cuDNN version greater than 7.2 (but note that this version should be compatible with your specific install of CUDA). My problem was that I was unwittingly using CUDA 10.0, which I think is theoretically compatible with tensorflow-gpu (based on cursory searches, it seems to work for some people), but didn't work for me at all.
Long story short, here is exactly the setup/process that worked for me:
CUDA compatible GPU (https://developer.nvidia.com/cuda-gpus to check yours specifically
python 3.5.4
tensorflow-gpu version 1.12.0
CUDA 9.0
CUPTI (again, this is included with your CUDA 9.0 install)
cuDNN 9.0 version 7.4.1.5. To install this correctly, make sure the .dll in /bin gets copied into the /bin folder of Cuda 9, the .h file from /include gets copied into the Cuda 9 /include folder, and the .lib file from /lib/x64 folder gets copied into the /lib/x64 folder for Cuda 9 (this all seems self evident, but oddly some installation guides I've seen only reference copying the .dll over).
visual c++ 2017
Microsoft Visual C++ 2015 Redistributable Update 3 (this can be found under 'Redistributables and Build Tools' here: https://visualstudio.microsoft.com/vs/older-downloads/). Do note that to install this I had to go into programs and settings and manually uninstall the visual c++ 2017 redistributable that was installed when I installed visual c++ to begin with.
Include both CUDA 9 and CUPTI in your path (CUDA (and cuDNN) for me was in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin, and CUPTI was in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\extras\CUPTI\libx64)
After all this importing tensorflow worked fine for me.
I honestly hope this helps someone out there, as this process was incredibly arduous for me personally and I'd love to be able to lessen that for someone else.

VirtualEnv tensorflow with Nvidia GPU : cuda-9.0-vs-cuda-8.0, cuDNN-7.0-vs-cuDNN-6.0

Today I installed tensorflow using the RTFM tensorflow dot org install linux,
I installed the VirtualEnv + Python3 + CPU and tested tensorflow Hello World, which worked fine.
Then I went on the nvidia path (GPU GTX 970) to install VirtualEnv + Python + GPU. RTFM (docs dot nvidia dot com cuda cuda-installation-guide-linux index dot html) , cuda-9.0, cuDDN 7, all PATH's are okay, .bashrc up-to-date, printenv LD_LIBRARY_PATH ok.
My GPU has been ok with the cuda scripts deviceQuery and bandwitdhTest. All post-installation-actions from the Nvidia checklist passed.
When I run Hello World in VirtualEnv+Python3+GPU, code below is what I get (cliffnote : tensorflow wants to use some cudalibrary-8.0 from the /usr/local/cuda-9.0/lib64 which is a 9.0 directory. I tried to add a symlink so cudalibrary-8.0 points to 9.0, but then I get the same message with another cudalibrary... doing this trick for all the cuda libraries is not what I call a fix ;-) )
alexandre#Martin-2:~/Documents/Ordinateur/VirtualEnv$ source tensorflow_py3_gpu/bin/activate
(tensorflow_py3_gpu) alexandre#Martin-2:~/Documents/Ordinateur/VirtualEnv$ python
Python 3.5.2 (default, Sep 14 2017, 22:51:06) [GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> # Python
... import tensorflow as tf
Traceback (most recent call last):
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcublas.so.8.0: cannot open shared object file: No such file or directory
Last line above is about the cudalibrary-8.0 that obviously is NOT in the list of the cudalibrary-9.0. Below is the rest of it.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/home/alexandre/Documents/Ordinateur/VirtualEnv/tensorflow_py3_gpu/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcublas.so.8.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https tensorflow dot org slash install slash install_sources hashtag common_installation_problems for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.
>>> hello = tf.constant('Hello, TensorFlow!')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'tf' is not defined
>>> sess = tf.Session()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'tf' is not defined
>>> print(sess.run(hello))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'sess' is not defined
>>> quit()
(tensorflow_py3_gpu) alexandre#Martin-2:~/Documents/Ordinateur/VirtualEnv$ deactivate`
--
Next day update
Not so clean fix : Create a link in /usr/local/cuda/lib64/ for every library with the wrong number version, linked to the right number version.
alexandre#Martin-2:/usr/local/cuda/lib64$ sudo ln -s libcurand.so.9.0 libcurand.so.8.0
I did this with five cuda libraries (libcusolver, libcublas, libcudart, libcurand, libcufft) and with the cuDNN library libcudnn (version 6 --> version 7).
Hello world! tensorflow worked... but if someone can tell me why tensorflow calls cuda-8.0 and cuDDN-6.0 libraries when I only installed cuda-9.0 and cuDDN-7.0, you're very welcome.
[SOLVED... OR NEARLY] UPDATE
I found https://github.com/tensorflow/tensorflow/issues/12052 that explains almost it all.
Cliffnote :
tensorflow-1.3 uses cuda-8.0 and cuDNN-6.0 (this is why these libraries are linked explicitly when I run tensorflow). I got tricked on the nvidia site that made me download the cuda-9.0 and cuDNN-7.0 versions, which will not be implemented in tensorflow-1.3.
tensorflow-1.4 will work with the cuda-9.0 and cuDNN-7.0 versions. tensorflow-1-4 may be available sometime in October 2017 (or anytime soon, check the link above).
Have you tried
sudo apt install cuda-8-0
?
It should download packages from http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604
Along with installing cudnn6 (the same way I installed cudnn7), it worked for me.

Tensorflow: ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory

I'm having problems in importing tensorflow in python3:
>>> import tensorflow as tf
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
I am using Nvidia drivers version 381.09 beta, as version 375 has this bug: https://askubuntu.com/questions/896221/strange-artifacts-along-window-borders-after-waking-computer-from-sleep-mode?noredirect=1&lq=1
I have install CUDA 8.0 and cuDNN-v6.0:
rharish#rharish-GL552VW:~$ cd /usr/local
rharish#rharish-GL552VW:/usr/local$ ls
bin cuda etc include man share
computecpp cuda-8.0 games lib sbin src
Also, libcusolver.so.8.0 exists in /usr/local/cuda/lib64/:
libcusolver.so.8.0 in 'ls' output
I have uninstalled and reinstalled CUDA, cuDNN, and built tensorflow from sources. This problem has been occuring since updating the Nvidia drivers to version 381.09 beta. Any help?
Found the solution:
I reinstalled nvidia-381, CUDA-8.0 (using the runfile) and cuDNN 6.0. Then I added the following in my .bashrc:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
No need for reinstallation. Install nvidia-cuda-dev:
sudo apt install nvidia-cuda-dev
Install cuDNN (which you download from https://developer.nvidia.com/cudnn), and set LD_LIBRARY_PATH accordingly (to cuda/lib64).
You could be having this problem if you installed the latest version of CUDA (9.0). If this is the case, you'll have the libcusolver.so.9.0 file or directory on your computer, but not 8.0, so python can't find it to import. Tensorflow doesn't yet support CUDA 9.0 (as of Oct 18th 2017).
To fix this, install CUDA 8.0, which can be found here. You can find all their legacy releases at the bottom of the main download page.
I faced this error due to incompatibility between Tensorflow version with CUDA.
I had tensorflow_gpu-1.3.0, CUDA 9 and cuDNN 7 which are incompatible as per this https://www.tensorflow.org/install/source#tested_build_configurations
so I uninstalled tensorflow_gpu-1.3.0 and installed tensorflow_gpu-1.5.0 and it worked fine
In addition to having the paths correctly set, the version of Tensorflow you have installed must be compatible with the CUDA driver version you have in your system otherwise it won't work.
See the link