0
votes

I am trying to use Keras Sequential, however, my jupyter notebook is flooded with error as it's not able to import tensorflow in the backend (i think). Later I found that, its not with Keras, but I am not able to do 'import tensorflow as tf' as well.

Any suggestions, please? I am using python 3.5.6 tensorflow 1.12

I did, pip install tensorflow for installation.

ImportError Traceback (most recent call last) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in swig_import_helper() 17 try: ---> 18 fp, pathname, description = imp.find_module('_pywrap_tensorflow', [dirname(file)]) 19 except ImportError:

~\AppData\Local\Continuum\anaconda3\lib\imp.py in find_module(name, path) 295 else: --> 296 raise ImportError(_ERR_MSG.format(name), name=name) 297

ImportError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python__init__.py in 53 # use dlopen() for dynamic loading. ---> 54 from tensorflow.python import pywrap_tensorflow 55 except ImportError:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in 27 return _mod ---> 28 _pywrap_tensorflow = swig_import_helper() 29 del swig_import_helper

~\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in swig_import_helper() 19 except ImportError: ---> 20 import _pywrap_tensorflow 21 return _pywrap_tensorflow

ModuleNotFoundError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last) in ----> 1 import tensorflow as tf

~\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow__init__.py in 22 23 # pylint: disable=wildcard-import ---> 24 from tensorflow.python import * 25 # pylint: enable=wildcard-import 26

~\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python__init__.py in 58 please exit the tensorflow source tree, and relaunch your python interpreter 59 from there.""" % traceback.format_exc() ---> 60 raise ImportError(msg) 61 62 # Protocol buffers

ImportError: Traceback (most recent call last): File "C:\Users\ritesh.kankonkar\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper fp, pathname, description = imp.find_module('_pywrap_tensorflow', [dirname(file)]) File "C:\Users\ritesh.kankonkar\AppData\Local\Continuum\anaconda3\lib\imp.py", line 296, in find_module raise ImportError(_ERR_MSG.format(name), name=name) ImportError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\ritesh.kankonkar\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python__init__.py", line 54, in from tensorflow.python import pywrap_tensorflow File "C:\Users\ritesh.kankonkar\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 28, in _pywrap_tensorflow = swig_import_helper() File "C:\Users\ritesh.kankonkar\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper import _pywrap_tensorflow ModuleNotFoundError: No module named '_pywrap_tensorflow'

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.

1

1 Answers

0
votes

Well, I am answering my own question since the error seems to have multiple causes. I am not sure what was the cause, however, after downgrading python to 3.5 and installing tensorflow with pip (pip install tensorflow), resolved the issue.

Note: I uninstalled everything before installing Anaconda again.