"import keras.models" error json

2,239 views
Skip to first unread message

gipe...@gmail.com

unread,
Apr 1, 2016, 1:32:20 PM4/1/16
to Keras-users
Hello!
I already instal keras on ubuntu 14.04 and try example mnist_cnn.py.
So i have error in 
"from keras.models import Sequential"
error:
" File "/home/user/anaconda2/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded") "

Matthew Hanson

unread,
Apr 13, 2016, 10:51:55 PM4/13/16
to Keras-users, gipe...@gmail.com
Getting the same error here:

>>> from keras.models import Sequential
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 5, in <module>
    from . import backend as K
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/__init__.py", line 24, in <module>
    _config = json.load(open(_config_path))
  File "/usr/lib/python2.7/json/__init__.py", line 290, in load
    **kw)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Successfully got Keras to work on another machine, not sure why it isn't working on this one. TensorFlow imports fine.

Matthew Hanson

unread,
Apr 13, 2016, 10:56:37 PM4/13/16
to Keras-users, gipe...@gmail.com
Aaaand of course the moment after I posted on here I found the error. My ~/.keras/keras.json file was messed up.

Naimish Agarwal

unread,
Jun 25, 2016, 4:51:10 AM6/25/16
to Keras-users, gipe...@gmail.com
I resolved the error as follows:

1. pip uninstall keras
2. delete .keras folder in your home directory
3. re-install keras from GitHub repository
4. import keras (to re-create .keras folder)

Hope it helps!

z.shu...@gmail.com

unread,
Jul 29, 2016, 5:13:50 PM7/29/16
to Keras-users, gipe...@gmail.com
Worked for me! I tried a few times previously, but didn't do step2... After deleting .keras from home directory, the re-installation worked.

I had keras work initially, but then I changed the backend from theano to tensorflow by editing keras.json file in .keras folder. It was after that, the "json error" occurred when I tried to import keras in python. I guess the keras.json file was messed up somehow...
Reply all
Reply to author
Forward
0 new messages