8

I am trying to import the module keras.utils.data_utils but its not working. However, I can find this module here. It is indeed existing. Why I cannot import it while I can import some other modules likekeras.models and keras.layers.core?

cliu@cliu-ubuntu:bin$ python
Python 2.7.9 (default, Apr  2 2015, 15:33:21) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> from keras.models import Sequential 
>>> from keras.layers.core import Dense, Activation, Dropout 
>>> from keras.layers.recurrent import LSTM
>>> from keras.utils.data_utils import get_file
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named data_utils

Edit:

See here for the answer.

Community
  • 1
  • 1
fluency03
  • 2,637
  • 7
  • 32
  • 62
  • why did you include the `python-3.x` tag if you are clearly using vs 2.7? and can you just `import keras` without error? – Tadhg McDonald-Jensen Mar 10 '16 at 00:22
  • 1
    when i did `pip install keras` it did not appear to install with that module, but when i downloaded the zip and did `python setup.py install` it installed correctly – Tadhg McDonald-Jensen Mar 10 '16 at 00:28
  • @TadhgMcDonald-Jensen I can import `keras` other modules like what I have edited in the question. – fluency03 Mar 10 '16 at 00:33
  • 1
    if you installed it with pip it would have pulled the code from [here](https://pypi.python.org/pypi/Keras/0.1.3) which says it was uploaded at 2015-08-27 but if you look at the [github history](https://github.com/fluency03/keras/commits/master/keras/utils/data_utils.py) it was only adapted 3 days ago. – Tadhg McDonald-Jensen Mar 10 '16 at 00:39
  • @TadhgMcDonald-Jensen can I update it to the latest version without reinstalling it using ./setup.py? – fluency03 Mar 10 '16 at 00:41
  • nope. thats what updating means. – Tadhg McDonald-Jensen Mar 10 '16 at 00:45
  • 1
    oh! the one in pypi has it in datasets so you would do `import keras.datasets.data_utils`, although expect that to change considering the github – Tadhg McDonald-Jensen Mar 10 '16 at 00:50
  • @TadhgMcDonald-Jensen it is working when I just use `python`, but it is not working in my eclipse. Do you know how to update my eclipse? I have tried to restart the application and create a new project. Both of them are not working. – fluency03 Mar 10 '16 at 08:48

4 Answers4

11

Even though this answer is correct but is not complete. Thanks to Ben J.'s answer but Tadhg McDonald-Jensen is the first one offering me the answers here.

Summarize it

I was using pip install keras to install keras, but it did not install the latest version of keras according to this. That is why I could do things like from keras.models import Sequential, from keras.layers.core import Dense, Activation, Dropout, and from keras.layers.recurrent import LSTM but not from keras.utils.data_utils import get_file. Because it is not in the previous versions.

SO, just clone the keras from their github, cd into it, and run sudo python setup.py install will solve this problem.

REMEMBER, if you already did this pip install keras, you have to make sure clear all keras versions you have installed by doing this pip uninstall keras many time until no keras existing, then do this sudo python setup.py install.

Community
  • 1
  • 1
fluency03
  • 2,637
  • 7
  • 32
  • 62
3

I looked at the tar.gz from https://pypi.python.org/pypi/Keras/0.1.3 and there is no file named data_utils.py in the utils folder. However the github does include this file: https://github.com/fchollet/keras.

Ben J.
  • 66
  • 4
0

I hope your issue is resolved by now, if not:

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

should do the job for you.

Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
Anuj Gupta
  • 6,328
  • 7
  • 36
  • 55
0

this might solve your problem.

sudo -H  pip3 install git+https://github.com/fchollet/keras.git --upgrade
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
deepgradient
  • 31
  • 1
  • 4