"Failed to load native TensorFlow runtime." - python

So I created a program to load a dataset from TensorFlow and I got an error that I have no idea what it means.
My code is:
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
data = keras.dataset_fashion_mnist
(train_images, train_labels), (test_images, test_labels) = data.data_load()
print(train_labels[1])
I supposed to get a number as output and not an error.
The error is:
Traceback (most recent call last):
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "helloworld.py", line 1, in <module>
import tensorflow as tf
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
from tensorflow_core import *
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
I have no idea what to do to solve this and what to try. I made sure that I have tensorflow installed and I do.
I think it has something to do with the library itseff.

Your error seems similar to this: https://github.com/tensorflow/tensorflow/issues/22794
The general solution there is to use a specific version of CUDA with a specific version of tensorflow, e.g.
tensorflow-gpu==1.14.0
python 3.6.8
CUDA v10.0
cudnn 7.4.1.5
Can you provide your library version? I'd recommend using conda to install tensorflow on Windows as it helps a lot with installing the right versions instead of setting things up yourself.
Edit
Please try these steps (Taken from Tensorflow's document: https://www.tensorflow.org/install/pip)
Go to the Visual Studio downloads: https://visualstudio.microsoft.com/vs/older-downloads/
Select Redistributables and Build Tools
Download and install the Microsoft Visual C++ 2015 Redistributable
Update 3
Enable long paths on windows: https://superuser.com/questions/1119883/windows-10-enable-ntfs-long-paths-policy-option-missing
Finally, please make sure your CPU supports AVX instructions: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#CPUs_with_AVX

Related

libcublas.so.9.0 No such file or directory

An error occurs when importing tensorflow.
My environment
Ubuntu 18.04 Desktop
Nvidia graphic driver 470.42.01
CUDA 11.4
Python 3.6.14 (Anaconda)
TensorFlow-gpu 1.12.0
CUDA environment variable setup completed (11.4)
Linked symbolic link at /usr/local/CUDA from /usr/local/CUDA-11.4
(The reason for using the old version is that the SDK of the project was written in the past.)
When importing tensorflow after running Python, the following error occurs:
>>> import tensorflow
Traceback (most recent call last):
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/(username)/anaconda3/envs/mdk/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 "/home/(username)/anaconda3/envs/mdk/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.9.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 "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/(username)/anaconda3/envs/mdk/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 "/home/(username)/anaconda3/envs/mdk/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
I installed CUDA 9.0 to fix this error.
However, the same error came out with version 7.0.
Do I need to install all the versions of CUDA that I need?
Or is there any other way to solve this?
According to Tensorflow documentation, TF v1.12 requires CUDA 9.0.
Take a look at screenshot for information,
Once Appropriate CUDA version installed, Add the CUDA®, CUPTI, and cuDNN installation directories to the %PATH% environmental variable.
Follow the installation steps mentioned here and change CUDA versions as per the requirement i.e CUDA 9.0.

What causes Tensorflow Import Error: DLL load failed?

I am using Anaconda environment on Windows 10. I have installed tensorflow-gpu using pip and when I try to import tensorflow, I get this import error below. I have tried to use cpu version of tensorflow and to reinstall all packages with new conda environment. My python is version 3.7 and tensorflow-gpu version 2.1.0.
>>> import tensorflow as tf
Traceback (most recent call last):
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\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\ossik\anaconda3\envs\tensorflow-gpu\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: Määritettyä osaa ei löydy.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
from tensorflow_core import *
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\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\ossik\anaconda3\envs\tensorflow-gpu\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: Määritettyä osaa ei löydy.
Failed to load the native TensorFlow runtime.
Do you have any idea what causes this error?
Try to downgrade and install tensorflow.
pip install tensorflow==2.0
if you use gpu
pip install --upgrade tensorflow-gpu==2.0
or try downloading these visual studio files
click here
This could be because you have a CPU(probably old), which can not support AVX instructions (for example, Intel Pentium or similar). You could solve this problem using this approach:
pip3 uninstall tensorflow
Go here: link with tensorflow 2.1.0 wheels which has been precompiled with SSE2 instructions.
Download wheel to your project, then install tensorflow using pip install <filename.wheel>.
And try again - error should be solved

python Tensorflow ImportError

Please help me with this error:
import tensorflow as tf Traceback (most recent call last): File
"/home/user/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py",
line 41, in
from tensorflow.python.pywrap_tensorflow_internal import * File "/home/user/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py",
line 28, in
_pywrap_tensorflow_internal = swig_import_helper() File "/home/user/anaconda3/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
"/home/user/anaconda3/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file) File "/home/user/anaconda3/lib/python3.6/imp.py", line 343, 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 "", line 1, in
File
"/home/user/anaconda3/lib/python3.6/site-packages/tensorflow/init.py",
line 24, in
from tensorflow.python import * File "/home/user/anaconda3/lib/python3.6/site-packages/tensorflow/python/init.py",
line 49, in
from tensorflow.python import pywrap_tensorflow File "/home/user/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py",
line 52, in
raise ImportError(msg) ImportError: Traceback (most recent call last): File
"/home/user/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py",
line 41, in
from tensorflow.python.pywrap_tensorflow_internal import * File "/home/user/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py",
line 28, in
_pywrap_tensorflow_internal = swig_import_helper() File "/home/user/anaconda3/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
"/home/user/anaconda3/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file) File "/home/user/anaconda3/lib/python3.6/imp.py", line 343, 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.
You could try that:
Confirm the python interpreter path, is anaconda or system python?
export python library export PYTHONPATH=xxxxx:$PYTHONPATH to solve some lib couldn't find before execute a python script in terminal.
If you following two step, above troubles could be solved.
Before importing TensorFlow, you need to install TensorFlow on Python 3.6.
Firstly, I assumed that you use the Windows operating system because you did not explain any information about your computer.
Open the Anaconda prompt, install TensorFlow with this command:
pip install tensorflow==2.0
If everything installs successfully, you can import the TensorFlow library in Python.
import tensorflow as tf

TensorFlow issues with running with Python 3.6

so trying to use TF to run through terminal to train images but receive this similar error. I know it's because TensorFLow is currently formatted to run with Python 3.5 and not 3.6 at this time.
Possible solutions, should I delete Python 3.6 and reinstall 3.5 with Anaconda?
Traceback (most recent call last):
File "/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Users/Mari/miniconda3/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/Mari/miniconda3/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Users/Mari/miniconda3/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: #rpath/libcublas.8.0.dylib
Referenced from: /Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
Reason: image not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Users/Mari/miniconda3/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/Mari/miniconda3/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Users/Mari/miniconda3/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: #rpath/libcublas.8.0.dylib
Referenced from: /Users/Mari/miniconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
Reason: image not 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
It says Reason: image not found in your code. Are you sure that you are just not having a wrong file path to your image? Did you try to just run import tensorflow as tf and sess = tf.Session() to see if Tensorflow initializes correctly?
Please also always add which system you are running. In general I would recommend to create a virtual environment with a specific python version set, to run tensorflow in. See here:
https://conda.io/docs/user-guide/tasks/manage-environments.html

Unable to use tensorflow

I installed tensorflow on my mac via pip and I'm using anaconda as my IDE.
when I run the command
import tensoflow
I'm getting the following error:
Traceback (most recent call last):
File "<ipython-input-3-a649b509054f>", line 1, in <module>
import tensorflow
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Applications/anaconda3/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 "/Applications/anaconda3/lib/python3.5/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Applications/anaconda3/lib/python3.5/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: #rpath/libcublas.8.0.dylib
Referenced from: /Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
Reason: image not 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 also ran pip list in my terminal to check if it was installed properly.
It lists all the tensorflow libraries that I have installed.
I'm using Anaconda v1.6.8 and Spyder v3.2.3
I can see that you have 2 versions of tensorflow. with (1.1.0) and without (1.3.0) gpu support. But error you are getting is because the gpu libraries are not properly installed.
For tensorflow-gpu==1.1.0 follow these instructions.
Unfortunatelly tensorflow dropped support for gpu on Mac since v1.2, but this answer may help you setup for a higher version.

Categories