简体   繁体   English

Keras:ImportError:没有名为data_utils的模块

[英]Keras: ImportError: No module named data_utils

I am trying to import the module keras.utils.data_utils but its not working. 我试图导入模块keras.utils.data_utils但它无法正常工作。 However, I can find this module here . 但是,我可以在这里找到这个模块。 It is indeed existing. 它确实存在。 Why I cannot import it while I can import some other modules like keras.models and keras.layers.core ? 为什么我不能导入它,而我可以导入一些其他模块,如keras.modelskeras.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. 请看这里的答案。

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 . 感谢Ben J.的回答,但是Tadhg McDonald-Jensen是第一个在这里给我答案的人。

Summarize it 总结一下

I was using pip install keras to install keras , but it did not install the latest version of keras according to this . 我使用pip install keras来安装keras ,但是根据这个没有安装最新版本的keras 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 . 这就是为什么我可以做一些事情,比如from keras.models import Sequentialfrom keras.layers.core import Dense, Activation, Dropoutfrom keras.layers.recurrent import LSTM但不是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. 所以,只需从他们的github clone kerascd进入它,并运行sudo python setup.py install将解决这个问题。

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 . 记住,如果你已经完成了这个pip install keras ,你必须确保通过执行这个pip uninstall keras很多时间清除你已经安装的所有keras版本,直到没有keras存在,然后执行这个sudo python setup.py install

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. 我查看了https://pypi.python.org/pypi/Keras/0.1.3中的tar.gz,并且utils文件夹中没有名为data_utils.py的文件。 However the github does include this file: https://github.com/fchollet/keras . 但是github包含这个文件: https//github.com/fchollet/keras

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. 应该为你做的工作。

这可能会解决您的问题。

sudo -H  pip3 install git+https://github.com/fchollet/keras.git --upgrade

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM