Reputation: 701
I am trying to use Keras in Anaconda Python on my 64 bit Windows 10 computer that does not have a GPU(I don't know if that is significant or not). I called pip install keras
and that seemed to install smoothly. However calling import keras
gives this error:
Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\jsmith\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 "C:\Users\jsmith\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\jsmith\anaconda3\lib\imp.py", line 342, 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 "C:\Users\jsmith\anaconda3\lib\site-packages\keras\__init__.py", line 3, in <module>
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\jsmith\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 "C:\Users\jsmith\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\jsmith\anaconda3\lib\imp.py", line 342, 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/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\jsmith\Desktop\Code\JohnWorkspaces\Machine_Learning\BeginningWithPydev\main\main.py", line 1, in <module>
import keras
File "C:\Users\jsmith\anaconda3\lib\site-packages\keras\__init__.py", line 6, in <module>
'Keras requires TensorFlow 2.2 or higher. '
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow
So I go and install tensorflow using pip install tensorflow
. It seems to take a while, though eventually it installs, yet does nothing to fix my problem, and still gives me the above error. Calling import tensorflow
gets me this error:
Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\jsmith\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 "C:\Users\jsmith\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\jsmith\anaconda3\lib\imp.py", line 342, 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 "C:\Users\jsmith\Desktop\Code\JohnWorkspaces\Machine_Learning\BeginningWithPydev\main\main.py", line 1, in <module>
import tensorflow
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\jsmith\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 "C:\Users\jsmith\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\jsmith\anaconda3\lib\imp.py", line 342, 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/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
The only solutions I have found for this issue are downgrading TensorFlow and installing Visual Studio. I have heard that Visual Studio is a very large program and would like to refrain from installing it. As for downgrading TensorFlow, I feel there should be a better solution. What is it about Visual Studio that makes TensorFlow work, and is there a way I can get that(Certain DLLs or dependencies) without having to get everything else along with Visual Studio? These are links to places I have seen this:
2.https://github.com/tensorflow/tensorflow/issues/35749
3.https://medium.com/@mdiqbalbajmi00786/importerror-keras-requires-tensorflow-2-2-e9f128c5fbf6
Upvotes: 1
Views: 1359
Reputation: 1197
According to tensorflow installation, you should have pre installed C++ redistributable for windows 7 or later.
Also you can directly download the tensorflow wheel from here just make sure to choose correct operating system, architecture and python version while downloading. Then you can do
pip install path_t_wheel_file.whl
I have heard that Visual Studio is a very large program and would like to refrain from installing it.
You do not have to install entire visual studio just the C++ redistributable
What is it about Visual Studio that makes TensorFlow work,
I haven't looked into tensorflow's source code but I think It is written in C++
so it requires additional libs that are provided by the c++ redistributables
Upvotes: 1
Reputation: 468
This may help
create new environment don't install packages in base environment (optional but it fixed tensorflow installation bugs for me)
conda install -c conda-forge tensorflow
to install tensorflow
then pip install keras
or conda install -c conda-forge keras
Upvotes: 0