Keras not importing - python

import tensorflow as tf
Traceback (most recent call last):
File "<ipython-input-30-64156d691fe5>", line 1, in <module>
import tensorflow as tf
File "E:\Users\Rajesh\Anaconda3\lib\site-packages\tensorflow__init__.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "E:\Users\Rajesh\Anaconda3\lib\site-packages\tensorflow\python__init__.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "E:\Users\Rajesh\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "E:\Users\Rajesh\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "E:\Users\Rajesh\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "E:\Users\Rajesh\Anaconda3\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 "E:\Users\Rajesh\Anaconda3\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "E:\Users\Rajesh\Anaconda3\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed with error code -1073741795
Failed to load the native TensorFlow runtime.

Is it keras or tensorflow ?
for making both work, uninstall both
conda remove tensorflow
conda remove keras
Remove it from local env as well
python3 -m pip uninstall tensorflow
python3 -m pip uninstall keras
From global env too
sudo python3 -m pip uninstall tensorflow
sudo python3 -m pip uninstall keras
Then do
python3 -m pip install tensorflow==1.8.0 --user

Related

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

Tensorflow installation issue: ImportError: DLL load failed with error code -1073741795

I am unable to install and import Tensorflow on my PC. I have tried the below approach as mentioned on https://www.tensorflow.org/install/pip#package-location. I have also tried installation using Conda but the same problem appears. MS Visual C++ is also installed as mentioned on https://www.tensorflow.org/install/pip#package-location
System information
OS Platform: Windows 7 Service Pack1 TensorFlow installed from (source
or binary):
https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp35-cp35m-win_amd64.whl
TensorFlow version: 1.12 Python version: 3.5.4 64-bit Installed using
virtualenv
Traceback (most recent call last):
File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in from
tensorflow.python.pywrap_tensorflow_internal import * File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28,
in
_pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24,
in swig_i mport_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, descript ion) File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\im
p.py", line 243, in load_module return load_dynamic(name, filename,
file) File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\im
p.py", line 343, in load_dynamic return _load(spec) ImportError: DLL
load failed with error code -1073741795
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow_init_.py", line 24, in from tensorflow.python
import pywrap_tensorflow # pylint: disable=unused-im port File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python_init_.py", line 49, in from
tensorflow.python import pywrap_tensorflow File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg) ImportError: Traceback (most recent call last):
File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in from
tensorflow.python.pywrap_tensorflow_internal import * File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28,
in
_pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24,
in swig_i mport_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, descript ion) File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\im
p.py", line 243, in load_module return load_dynamic(name, filename,
file) File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\im
p.py", line 343, in load_dynamic return _load(spec) ImportError: DLL
load failed with error code -1073741795
If your CPU didn't support AVX instructions, you will get ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed. (Win 10) or ImportError: DLL load failed with error code -1073741795 (Win 7) when using tensorflow official release 1.6.0 and up (pip install tensorflow)
You can use pip install [filename].whl which file download from sse2 folder instead of using official AVX binary.
Please verify whether the below command is working.
pip3 install --upgrade tensorflow
You can use the below link for reference of tensorflow-windows-wheel.
https://github.com/fo40225/tensorflow-windows-wheel
I have built tensorflow wheel without AVX.
https://github.com/fo40225/tensorflow-windows-wheel/tree/master/1.6.0/py36/CPU/sse2
I wish this .whl may help you.
You can install the wheel file with pip. First change the current directory to install location. Then,
pip install tensorflow-1.6.0-cp36-cp36m-win_amd64.whl
If its not working please try to resolve it by downgrading protobuf from 3.6.1 to 3.6.0:
pip install protobuf==3.6.0
Got it fixed post looking for similar answers in internet...I had to install the tensorflow version 1.5 and the tensorflow backend loaded seamlessly

how to install older versions of tensor flow

I am getting headache with tensorflow installations...
I have CUDA 8, CUdnn 6 and UBUNTU 16.04, python 2.7
I want now to install yensorflow. I have followed what they have explained for installation on the website but I have version ismatches of libraries.
As I am using caffe, I do not want to change those versions. So I have to go for older versions of tensorflow it seems.
But I can not find a good way to install it. Every time it is just failuare. I am very tired now.
I go like this:
1- download tensorflow r1.4 from here:
https://github.com/tensorflow/tensorflow/tree/r1.4
2- My 'LD_LIBRARY_PATH' is:
:/usr/local/cuda-8.0/lib64/:/usr/local/cuda/lib64:/home/aa/torch/install/lib:/usr/lib/
3- The I run successfully this:
$ sudo apt-get install python-pip python-dev python-virtualenv # for Python 2.7
4- and this:
$ virtualenv --system-site-packages targetDirectory # for Python 2.7
5- I activate the environment
$ source ~/tensorflow/bin/activate
6- and this
(tensorflow)$ easy_install -U pip
Till here, everything is fine.
7- and when I run this line
pip install --upgrade tensorflow-gpu
It finished successfully with this message:
Successfully installed absl-py-0.1.10 numpy-1.14.1 protobuf-3.5.1 setuptools-38.5.1 six-1.11.0 tensorflow-gpu-1.5.0 tensorflow-tensorboard-1.5.1 werkzeug-0.14.1 wheel-0.30.0
But then I cannot import it in python and this message is given:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/aa/tensorflow/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/aa/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/aa/tensorflow/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/aa/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/aa/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/aa/tensorflow/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
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 I should go for older versions.
I did install older versions
but then when I test installation in python I see this messages:
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/core/framework/node_def_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 22, in <module>
serialized_pb=_b('\n/tensorflow/core/framework/resource_handle.proto\x12\ntensorflow\"r\n\x13ResourceHandleProto\x12\x0e\n\x06\x64\x65vice\x18\x01 \x01(\t\x12\x11\n\tcontainer\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\thash_code\x18\x04 \x01(\x04\x12\x17\n\x0fmaybe_type_name\x18\x05 \x01(\tB/\n\x18org.tensorflow.frameworkB\x0eResourceHandleP\x01\xf8\x01\x01\x62\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/aa/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
ImportError: cannot import name pywrap_tensorflow
You should be able to install earlier versions of tensorflow using
pip install tensorflow==1.3 where 1.3 is the version number. You can pick the version of your choice.
you can find .whl file of tensorflow in here https://pypi.python.org/pypi/tensorflow/1.4.0 and install it using pip.
hope you looking tensorflow 1.4.0 version in case if you want older version change url https://pypi.python.org/pypi/tensorflow/1.x.0(x= version you want)
'The problem is solved.
I had "/usr/lib/python2.7/dist-packages" in my PYTHONPATH.
So there was a version mismatch between protobufs and it was solved by typing 'unset PYTHONPATH' before starting to import tensorflow.

Tensorboard error after installing via pip

I have recently attempted to install tensorboard via pip as detailed in the README.md. The installation was deemed successful however when I try to run tensorboard after the installation, I keep on receiving an import/undefined symbol error as seen below.
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorboard/tensorboard.runfiles/org_tensorflow/tensorflow/tensorboard/tensorboard.py", line 32, in <module>
from tensorflow.python.summary import event_file_inspector as efi
File "/usr/local/lib/python3.5/dist-packages/tensorboard/tensorboard.runfiles/org_tensorflow/tensorflow/python/summary/event_file_inspector.py", line 122, in <module>
from tensorflow.python.platform import gfile
File "/usr/local/lib/python3.5/dist-packages/tensorboard/tensorboard.runfiles/org_tensorflow/tensorflow/python/platform/gfile.py", line 22, in <module>
from tensorflow.python.lib.io.file_io import copy as Copy
File "/usr/local/lib/python3.5/dist-packages/tensorboard/tensorboard.runfiles/org_tensorflow/tensorflow/python/lib/io/file_io.py", line 27, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorboard/tensorboard.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorboard/tensorboard.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: /usr/local/lib/python3.5/dist-packages/tensorboard/tensorboard.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow.so: undefined symbol: PyBytes_AsStringAndSize
Have I missed something in the installation process?
What can I do to fix this?
Thanks!
above error is reported because Tensorboard is installed using pip3(python 3) and TF env is set to python2.7.
use pip2 install tensorboard
now tensorboard and tf env both set to python2

Error importing tensorflow

I installed tensorflow and CUDA using the .deb file. I also installed CUDNN. However, when I try to import the library in python, it is giving me this error.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 49, 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.7.5: cannot open shared object file: No such file or directory
I've added the following lines to my .bashrc file
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
and make sure that you have libcudart.so.7.5.lib inside that path.
Like fabrizioM mentioned, you must have the libcudart.so.7.5.lib inside /usr/local/cuda/lib64. To do that, follow the instructions given by TensorFlow:
tar xvzf cudnn-7.5-linux-x64-v5.1-ga.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Categories