1

I am trying to import keras it gives me an error from tensorflow.python.ops import tensor_array_ops.

>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ss/anaconda2/envs/kerasenv/lib/python2.7/site-packages/keras/__init__.py", line 2, in <module>
    from . import backend
  File "/home/ss/anaconda2/envs/kerasenv/lib/python2.7/site-packages/keras/backend/__init__.py", line 67, in <module>
    from .tensorflow_backend import *
  File "/home/ss/anaconda2/envs/kerasenv/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 4, in <module>
    from tensorflow.python.ops import tensor_array_ops
ImportError: cannot import name tensor_array_ops

I really appreciate if someone can help me to solve this error. Thanks.

S.EB
  • 1,966
  • 4
  • 29
  • 54
  • Which versions are you using? Python, keras and tf – Nassim Ben Mar 02 '17 at 13:47
  • Thanks for reply, it is not showing the keras version by this command `python -c "import keras; print keras.__version__"` . it is showing the same error, but python version is Python 2.7.13. It should be the latest version of keras which is `keras-1.2.2`. – S.EB Mar 02 '17 at 14:05
  • How about tensorflow? – Nassim Ben Mar 02 '17 at 14:09
  • when I am trying to check the tensorflow version by this command `python -c 'import tensorflow as tf; print(tf.__version__)'` , it is giving error: `Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute '__version__'` – S.EB Mar 02 '17 at 14:18
  • How did you install TF? – Nassim Ben Mar 02 '17 at 14:20
  • I was following the command from this [link](http://machinelearningmastery.com/introduction-python-deep-learning-library-keras/) . Indeed, that is the first time I am installing keras. Thanks – S.EB Mar 02 '17 at 14:22
  • 1
    This is just installing keras... you need to install a backend. Choose Tensorflow or Theano. – Nassim Ben Mar 02 '17 at 14:47

2 Answers2

1

Try: sudo pip install tensorflow --upgrade

You may be using an older version of TensorFlow.

Alex M
  • 2,756
  • 7
  • 29
  • 35
David Roth
  • 87
  • 3
  • 8
0

Did you install tensorflow at all? Could you try installing the lastest version? There is how:

pip install git+git://github.com/tensorflow/tensorflow  
pip install git+git://github.com/fchollet/keras.git --upgrade

If this doesn't work I do recommand using theano as a backend, it worked well for me. There is how to setup it easily:

pip install git+git://github.com/Theano/Theano  
pip install git+git://github.com/fchollet/keras.git --upgrade  
pip install tensor

Before you do anything else, start python and import keras. Once keras is imported a new file will be created. You can then execute this command:

vi .keras/keras.json

Once the file is open, change tensorflow for theano and you are ready to go.

Alex M
  • 2,756
  • 7
  • 29
  • 35