keras is not running even after installing tensorflow - python

i have installed "Anaconda3-2020.07-Windows-x86_64" and python "python-3.8.0". after that, i have installed keras and then tensorflow. but each time i am running the code "import keras" in spyder, the problem is showing that:
***Traceback (most recent call last):
File "C:\Users\Asus\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Asus\anaconda3\lib\site-packages\keras_init_.py", line 3, in
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
File "C:\Users\Asus\AppData\Roaming\Python\Python38\site-packages\tensorflow_init_.py", line 41, in
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\Asus\AppData\Roaming\Python\Python38\site-packages\tensorflow\python_init_.py", line 40, in
from tensorflow.python.eager import context
File "C:\Users\Asus\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\context.py", line 35, in
from tensorflow.python import pywrap_tfe
File "C:\Users\Asus\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Asus\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Asus\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: 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 "", line 1, in
import keras
File "C:\Users\Asus\anaconda3\lib\site-packages\keras_init_.py", line 5, in
raise ImportError(
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow
----------------------------------------------***
now, i dont know what is the problem mainly. because my tensorflow version shows that its 2.3.0..
i dont know what iis the problem. please, any one help.

From comments
I had to create a environment in anaconda, named the environment as
tensorflow, and created the environment based on python 3.6. In that
environment, i imported tensorflow, keras separately and installed the
spyder, jupyter notebook . after all these steps, it worked (paraphrased from kazi fahim lateef)
Steps to create virtual environment in anaconda
# Create environment
conda create --name TF
# When conda asks you to proceed, type y:
proceed ([y]/n)?
# Activate virtual environment
conda activate TF
# Install the TF Version
conda install tensorflow
# Install the Keras Version
conda install Keras
Note: From TF 2.0, onwards keras are integrated with TF. You can refer tf.keras module for more details.

Related

Faild to importing tensorflow [duplicate]

I ran through the TensorFlow object detection installation on Windows.
https://medium.com/riow/tensorflow-object-detection-on-windows-ad10bfde217c
After successfully installing TensorFlow object detection,
I ran following command to test, and receiving error below. How can this be fixed?
python object_detection/builders/model_builder_test.py
Error: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing pywrap_tensorflow_internal: The specified module could not be found.
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in
from object_detection.builders import model_builder
File "c:\testimage\models\research\object_detection\builders\model_builder.py", line 23, in
from object_detection.builders import anchor_generator_builder
File "c:\testimage\models\research\object_detection\builders\anchor_generator_builder.py", line 23, in
from object_detection.anchor_generators import flexible_grid_anchor_generator
File "c:\testimage\models\research\object_detection\anchor_generators\flexible_grid_anchor_generator.py", line 17, in
import tensorflow.compat.v1 as tf
File "C:\TestImage\models\venv\lib\site-packages\tensorflow_init.py", line 41, in
from tensorflow.python.tools import module_util as module_util
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python_init.py", line 40, in
from tensorflow.python.eager import context
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\eager\context.py", line 35, in
from tensorflow.python import pywrap_tfe
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in
from tensorflow.python import pywrap_tensorflow
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Currently using Python 3.8 with latest tensorflow, with tensorflow-cpu
tldr;
You need to install the C++ redistributable mentioned on the install page before installing TensorFlow so that TensorFlow can use it to generate code at install time.
Details:
I'm not an expert but it sounds like this was key:
The pywrap_tensorflow_internal.py module you are missing appears to me to be a SWIG-generated python interface to a C++ library, or something of that nature. My guess is, that file gets generated when you install TensorFlow (it reminds me of how some Ruby gems have to compile C++ when you install them, for whatever that's worth). Since you don't have that generated file, my guess is that the C++ package mentioned on the TensorFlow install page is needed for that code generation, so you need to have the C++ package installed before installing TensorFlow.
Totally a guess, but perhaps you installed the C++ package after TF. In that case, you should be able to uninstall TF, install the C++ package, and then install TF again.
Maybe a lingering question is if there were any indicative error messages on installing TF about the missing C++ package and if not, maybe there should be.

Tensorflow installation on Windows: DLL load failed while importing _pywrap_tensorflow_internal

I ran through the TensorFlow object detection installation on Windows.
https://medium.com/riow/tensorflow-object-detection-on-windows-ad10bfde217c
After successfully installing TensorFlow object detection,
I ran following command to test, and receiving error below. How can this be fixed?
python object_detection/builders/model_builder_test.py
Error: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing pywrap_tensorflow_internal: The specified module could not be found.
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in
from object_detection.builders import model_builder
File "c:\testimage\models\research\object_detection\builders\model_builder.py", line 23, in
from object_detection.builders import anchor_generator_builder
File "c:\testimage\models\research\object_detection\builders\anchor_generator_builder.py", line 23, in
from object_detection.anchor_generators import flexible_grid_anchor_generator
File "c:\testimage\models\research\object_detection\anchor_generators\flexible_grid_anchor_generator.py", line 17, in
import tensorflow.compat.v1 as tf
File "C:\TestImage\models\venv\lib\site-packages\tensorflow_init.py", line 41, in
from tensorflow.python.tools import module_util as module_util
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python_init.py", line 40, in
from tensorflow.python.eager import context
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\eager\context.py", line 35, in
from tensorflow.python import pywrap_tfe
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in
from tensorflow.python import pywrap_tensorflow
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Currently using Python 3.8 with latest tensorflow, with tensorflow-cpu
tldr;
You need to install the C++ redistributable mentioned on the install page before installing TensorFlow so that TensorFlow can use it to generate code at install time.
Details:
I'm not an expert but it sounds like this was key:
The pywrap_tensorflow_internal.py module you are missing appears to me to be a SWIG-generated python interface to a C++ library, or something of that nature. My guess is, that file gets generated when you install TensorFlow (it reminds me of how some Ruby gems have to compile C++ when you install them, for whatever that's worth). Since you don't have that generated file, my guess is that the C++ package mentioned on the TensorFlow install page is needed for that code generation, so you need to have the C++ package installed before installing TensorFlow.
Totally a guess, but perhaps you installed the C++ package after TF. In that case, you should be able to uninstall TF, install the C++ package, and then install TF again.
Maybe a lingering question is if there were any indicative error messages on installing TF about the missing C++ package and if not, maybe there should be.

i'm using python 3.7.7 but i have a problem while importing tensorflow

I'm new at python (version of python 3.7.7) and I'm trying to run a finished project, I imported everything but tensorflow is not working the error is shown down below:
Traceback (most recent call last): File
"C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import * 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
"C:/Users/User/Desktop/adsp/train.py", line 1, in <module>
import tensorflow as tf File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py",
line 41, in <module>
from tensorflow.python.tools import module_util as _module_util File
"C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\__init__.py",
line 39, in <module>
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 83, in <module>
raise ImportError(msg) ImportError: Traceback (most recent call last): File
"C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import * 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.
The issue is of compatibility. The version of tensorflow which you are trying to run with python 3.7 is not compatible with the same. In order to check for possible compatible versions please visit this link.
Also in case you are facing too many issues while trying to install some library in python and your work is getting held, I'd recommend you to make use of Google Colab.
There you won't need to worry about installation of packages. Although one must experience the installation and setup of packages as a learning.
Try uninstalling tensorflow from pip and reinstalling it again. It seems you have an import error. Also if you have two or more Python versions on your machine, this can cause issues sometimes

How do I install a previous version of Tensorflow on Google Colab?

I uninstalled the pre-installed version of Tensorflow on Google Colab by using !pip uninstall tensorflow -y and then !pip uninstall tensorflow-gpu -y. Then I installed the version I desired !pip install tensorflow-gpu==1.4.1 which seems to work and it outputs Successfully installed tensorflow-gpu-1.4.1. However, when I run !pip show tensorflow I get WARNING: Package(s) not found: tensorflow.
I've already tried restarting the runtime after installing Tensorflow but that didn't work. I am also running a GPU runtime.
Also, when I run:
import tensorflow as tf
print(tf.__version__)
I get the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow.py in <module>()
57
---> 58 from tensorflow.python.pywrap_tensorflow_internal import *
59 from tensorflow.python.pywrap_tensorflow_internal import __version__
10 frames
ImportError: libcublas.so.8.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow.py in <module>()
70 for some common reasons and solutions. Include the entire stack trace
71 above this error message when asking for help.""" % traceback.format_exc()
---> 72 raise ImportError(msg)
73
74 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python3.6/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.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.6/imp.py", line 343, 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://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.
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
How could I solve this problem to correctly install Tensorflow 1.4.1? I've already tried restarting the runtime after installing Tensorflow but that didn't work. I am also running a GPU runtime.
Try reinstalling tensorflow with the following commands
!pip uninstall tensorflow -y
!pip install tensorflow==1.14
then restart runtime when asked in colab. You should be able to import the correct version of TensorFlow.
%tensorflow_version 1.x
import tensorflow as tf
print(tf.__version__)
1.14.0

TensorFlow fails to load runtime after installation from source

I started compiling TensorFlow from source on Ubuntu Linux 16.06 LTS, running the commands from the TensorFlow Linux compilation instructions.
My CUDA and CuDNN setup works, as the pre-compiled TensorFlow nvidia-docker image works.
After using bazel to build the TensorFlow Python wheel, and then installing the wheel with pip, I get the following error message when trying to import TensorFlow:
>>> import tensorflow
Traceback (most recent call last):
File "/home/james/workspace/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/james/workspace/tensorflow/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/james/workspace/tensorflow/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/james/workspace/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/james/workspace/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
This error happens when you are running Python from the TensorFlow source directory after having installed the Python wheel.
A similar error happens when you try importing TensorFlow before installing the Python wheel.
The solution to this problem is to change your working directory to something else, while still remaining in the virtualenv that you installed the Python wheel to.

Categories

Resources