Keras module import error in spyder

0 views
Skip to first unread message

Rupert Young

unread,
Jul 22, 2016, 12:00:22 PM7/22/16
to Anaconda - Public
Hi,

I installed python 2.7 and keras.

Then having found out about spyder I installed anaconda.

When I first run a file with a keras module, I get this error

ImportError: No module named keras.layers


So I added  /usr/local/lib/python2.7/dist-packages to PYTHONPATH, and restart.

Then when I first run the command I get this error,
from keras.layers import Input, Dense
Using TensorFlow backend.
Traceback (most recent call last):

  File "<ipython-input-1-b5da44e251a5>", line 1, in <module>
    from keras.layers import Input, Dense

  File "/usr/local/lib/python2.7/dist-packages/keras/__init__.py", line 2, in <module>
    from . import backend

  File "/usr/local/lib/python2.7/dist-packages/keras/backend/__init__.py", line 60, in <module>
    from .tensorflow_backend import *

  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1, in <module>
    import tensorflow as tf

  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 58, in <module>
    raise ImportError(msg)

ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
    from google.protobuf import descriptor as _descriptor
ImportError: No module named google.protobuf


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.
If I run it again I get this error,

from keras.layers import Input, Dense
Using TensorFlow backend.
Traceback (most recent call last):

  File "<ipython-input-3-b5da44e251a5>", line 1, in <module>
    from keras.layers import Input, Dense

  File "/usr/local/lib/python2.7/dist-packages/keras/__init__.py", line 2, in <module>
    from . import backend

  File "/usr/local/lib/python2.7/dist-packages/keras/backend/__init__.py", line 60, in <module>
    from .tensorflow_backend import *

  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1, in <module>
    import tensorflow as tf

  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 48, in <module>
    from tensorflow.python import pywrap_tensorflow

ImportError: cannot import name pywrap_tensorflow

Any idea what is going wrong?

Regards,
Rupert

Carlos Córdoba

unread,
Jul 25, 2016, 11:13:41 AM7/25/16
to anac...@continuum.io
Hi,

You can't add a dist-packages directory from a different Python interpreter to your PYTHONPATH. What you need to do is to change your interpreter by following the steps mentioned in this answer:

http://stackoverflow.com/a/19813292/438386


Cheers,
Carlos

El 22/07/16 a las 11:00, 'Rupert Young' via Anaconda - Public escribió:
--
Anaconda Community Support Group Brought to you by Continuum Analytics
---
You received this message because you are subscribed to the Google Groups "Anaconda - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anaconda+u...@continuum.io.
To post to this group, send email to anac...@continuum.io.
Visit this group at https://groups.google.com/a/continuum.io/group/anaconda/.

Reply all
Reply to author
Forward
0 new messages