Tensorflow with CUDA: ImportError - python

I've installed TensorFlow step by step like described in this tutorial from NVIDIA (Ubuntu 16.04 Desktop, GTX 970):
http://www.nvidia.com/object/gpu-accelerated-applications-tensorflow-installation.html
Every steps completes without errors, but if I try to import TensorFlow in Python afterwards I'm always gettin' this error message:
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 72, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 61, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/dist-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.
I've installed the CUDA-Toolkit to /opt/cuda/toolkit (also cuDNN).
I already tried to symlink:
sudo ln -s /opt/cuda-toolkit /usr/local/cuda
sudo ln -s /opt/cuda-toolkit /usr/local/cuda-8.0
Or this:
sudo export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/cuda-toolkit/lib64:/opt/cuda-toolkit/extras/CUPTI/lib64
sudo export CUDA_HOME=/opt/cuda-toolkit
But the error remains. Can anybody give me a hint why this error occurs?
Thanks a lot :)

I had a similar problem on a machine with similar hardware (GTX 970M) and I solved it using the steps provided in the following post:
https://askubuntu.com/a/278840
The only difference in my case was that in the nvidia.conf file I added only the following line:
/usr/local/cuda-8.0/lib64
and then ran: sudo ldconfig
Hope it helps :)

Related

Error importing Tensorflow when import tensorflow as tf

I've recently gone through the installation of tensorflow (and struggled a little) and when I believed I had got it, I now get these import errors when running a file that ONLY contains import tensorflow as tf, I ran the cmd: python3 tftest.py and get these import errors:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
File "/usr/lib/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
ImportError: /usr/local/lib/python3.4/dist-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "stockprice.py", line 1, in <module>
import tensorflow as tf
File "/usr/local/lib/python3.4/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 60, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
File "/usr/lib/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
ImportError: /usr/local/lib/python3.4/dist-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header
Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.
I do have tensorflow installed
Name: tensorflow
Version: 0.12.0
Location: /usr/local/lib/python3.4/dist-packages
Requires: numpy, six, protobuf, wheel
I've been trying to figure this out for hours, has anyone encountered this or a similar error? I've looked at installation manuals, and followed every single step I could. I've tried reintalling protobuf
I am not running my test file on the tensorflow directory.
I would really REALLY appreciate any help since this error is draining my brain out.
Try to delete the library file manually and reinstall it using pip
check through pip list not to have installed the tensorflow-gpu library because some GPUs are not supported.
If this is the case, uninstall tensor flow-gpu and tensorflow-estimator and re-install tensorflow :
pip uninstall tensorflow-gpu
pip uninstall tensorflow-estimator
pip install tensorflow
make sure you use python 3.6 with the pip -V command
What I did was clicking
Runtime -> Restart Runtime
and running the code all over again, it worked like magic.

Installing Tensorflow 1.10 on El Capitan 10.11.6

I am trying to install tensorflow 1.10 on my old mac, but I run into the same problem every time. As soon as I start the python shell and I do get the error below.
I did try to install it in a virtualenv first, after that, I tried to install it just using pip and got the same error. Also when I tried to install it with conda, the same issue again. I googled and looked that up here, but couldn't solve it yet, maybe due to my noobish acting. I did uninstall anaconda and pip already and tried again, but I always run into the same error.
I do have CUDA installed, although I tried to install tensorflow with and without GPU.
The error results in: Failed to load the native TensorFlow runtime.
I hope someone is able to help, as I would really like to learn this.
(tensorflow) abc:~ me$ python
import tensorflow as tf
Traceback (most recent call last):
File "/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Users/me/tensorflow/lib/python3.6/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 "/Users/me/tensorflow/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Users/me/tensorflow/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _SecKeyCopyExternalRepresentation
Referenced from: /Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so (which was built for Mac OS X 10.12)
Expected in: /System/Library/Frameworks/Security.framework/Versions/A/Security
in /Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
During handling of the above exception, another exception occurred:
>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/__init__.py", line 22, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Users/me/tensorflow/lib/python3.6/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 "/Users/me/tensorflow/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Users/me/tensorflow/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _SecKeyCopyExternalRepresentation
Referenced from: /Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so (which was built for Mac OS X 10.12)
Expected in: /System/Library/Frameworks/Security.framework/Versions/A/Security
in /Users/me/tensorflow/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
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 think there is something wrong with TensorFlow 1.10 and OS X El Capitan (10.11.6)!
Just install 1.9.0 instead of 1.10 with the pip command:
pip3 install tensorflow==1.9.0
or its GPU version:
pip3 install tensorflow-gpu==1.9.0
It seems to be a version conflict. I can succesfully run Tensorflow 1.9.

Tensorflow can't be loaded

I installed tensorflow using pip (even different versions of tf), but whenever I'm loading it in the server, I get the following. I spent a whole day on this, couldn't figure out so far. Hopefully someone smart will do it easily!
> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/afs/umich.edu/user/b/m/bmodene/miniconda2/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import * # pylint: disable=redefined-builtin
File "/afs/umich.edu/user/b/m/bmodene/miniconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/afs/umich.edu/user/b/m/bmodene/miniconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/afs/umich.edu/user/b/m/bmodene/miniconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/afs/umich.edu/user/b/m/bmodene/miniconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/afs/umich.edu/user/b/m/bmodene/miniconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.17' not found (required by /afs/umich.edu/user/b/m/bmodene/miniconda2/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)
Failed to load the native TensorFlow runtime.
I tried following these instructions: https://www.tensorflow.org/install/install_sources#common_installation_problems
In the page you're referring to there is a section under "Build the pip package" saying:
NOTE on gcc 5 or later: the binary pip packages available on the TensorFlow website are built with gcc 4, which uses the older ABI. To make your build compatible with the older ABI, you need to add --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" to your bazel build command. ABI compatibility allows custom ops built against the TensorFlow pip package to continue to work against your built package.
It is unclear from your question if you built the package yourself, but if yes, have you tried this option?

ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory when installing tensor flow on Ubuntu 16.04.03

I am trying to install tensorflow with cuda and gpu support. When I try to import it, I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/srivishnu/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/srivishnu/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/srivishnu/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/srivishnu/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/srivishnu/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/srivishnu/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
this error occurs when I type this command in:
import tensorflow as tf
Can you please help me solve this problem
This is almost always a missing path in your LD_LIBRARY_PATH. Find libcublas.so.9.0 on your system (start looking under /usr/local).
If you don't find it, then install the CUDA 9.0 Toolkit (note that with TF 1.5 you want 9.0 and not 9.1, a common gotcha, at least common in-so-far as I made that mistake myself).
https://developer.nvidia.com/cuda-90-download-archive
If you have it, then update your LD_LIBRARY_PATH to point to the appropriate lib directory.
If you've done either of those and are now getting a similar looking error for a cudnn related library, then repeat that process for the CUDNN library.
https://developer.nvidia.com/cudnn
I think the latest version works. Tensorflow depends on both CUDA toolkit and the CuDNN library extension.
Note that you can install all of this in userspace too (sudo is typical, but not required).
To easily find the libcublas file, run sudo find / -iname 'libcublas*'. Then add the path to the folder containing that file into LD_LIBRARY_PATH.
I had cuda-9.0 installed and the LD_LIBRARY_PATH was pointing to the correct location. Turned out that the permission of the folder /usr/local/cuda-9.0 was wrong. I could not even cd to the folder. I changed the owner of the cuda-9.0 from root to my-user-name and after that python was able to find the missing library.

TensorFlow: libcudart.so.7.5: cannot open shared object file: No such file or directory

I am running TensorFlow on Ubuntu 15.10. When I enter pip show tensorflow, I see that TF has been installed properly.
However, when I write import tensorflow as tf, I get the following error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow import contrib
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/__init__.py", line 23, in <module>
from tensorflow.contrib import layers
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/__init__.py", line 68, in <module>
from tensorflow.contrib.layers.python.layers import *
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/__init__.py", line 22, in <module>
from tensorflow.contrib.layers.python.layers.initializers import *
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/initializers.py", line 24, in <module>
from tensorflow.python.ops import random_ops
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/random_ops.py", line 23, in <module>
from tensorflow.python.framework import ops
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 39, in <module>
from tensorflow.python.framework import versions
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/versions.py", line 22, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/home/me/anaconda2/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.7.5: cannot open shared object file: No such file or directory
For what it's worth, I have followed the instructions here and set my LD_LIBRARY_PATH and CUDA_HOME environment variables.
Any advice?
EDIT:
I have installed CUDA 7.5 and added these to my .profile file:
export LD_LIBRARY_PATH="/usr/local/cuda-7.5/lib64"
export CUDA_HOME=/usr/local/cuda-7.5
However, I continue to see the same error message.
EDIT:
I see the following output when I run ldd /usr/local/cuda-7.5/lib64/libcudart.so.7.5:
linux-vdso.so.1 => (0x00007ffdac7ea000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc27a281000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc27a07d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc279e5e000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc279c56000)
/lib64/ld-linux-x86-64.so.2 (0x00005604f5406000)
EDIT:
If it is relevant, I use GeForce GT640.
EDIT:
I followed #tommus' advice and called source ~/.profile before running TensorFlow, and now it works like a charm.
Thanks to everyone who tried to help me in the comments -- this is my first experience with any kind of Linux distribution, and I am really very appreciative of all the patient assistance I have received so far :-) You guys are absolutely awesome!
After editing .profile file you either need to log out and log back in or run the following command:
source ~/.profile
The solution is persistent so there is no need to perform it ever again.
sudo nano /etc/ld.so.conf.d/nvidia.conf
Add this:
/usr/local/cuda-8.0/lib64
/usr/local/cuda-8.0/lib
run
sudo ldconfig
if it works well ,please tell me.
If you are using pip but other answers did not work for you, try this.
In my case this exact problem was solved by reinstalling tensorflow using:
pip install tensorflow
Pip must have messed up its dependencies or something when installing other packages after Tensorflow installation (I've run pip install -r requirements.txt afterwards for my own purposes --> that broke Tensorflow).
You maybe need to update your cuDNN version as Tensorflow 1.3 doesn't work with cuDNN 5.1 or earlier. Download cuDNN 6.0 or upper and install to fix the issue
I had same error. I have to have Cuda 8.0 and CuDNN 5.1 for running some experiments!!
SOLUTION: Run python with Sudo Python
python
Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:55)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import tensorflow
Traceback (most recent call last):
File "", line 1, in
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.

Categories

Resources