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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35905264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:08:02  来源:igfitidea点击:

Keras: ImportError: No module named data_utils

pythonpython-2.7python-3.ximportkeras

提问by fluency03

I am trying to import the module keras.utils.data_utilsbut 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.modelsand keras.layers.core?

我正在尝试导入模块keras.utils.data_utils但它不起作用。但是,我可以在这里找到这个模块。它确实存在。为什么我不能导入它而我可以导入其他一些模块,比如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 herefor the answer.

看到这里的答案。

回答by fluency03

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

即使这个答案是正确的,但并不完整。感谢Ben J.的回答,但Tadhg McDonald-Jensen是第一个在这里为我提供答案的人。

Summarize it

总结一下

I was using pip install kerasto install keras, but it did not install the latest version of kerasaccording 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 LSTMbut not from keras.utils.data_utils import get_file. Because it is not in the previous versions.

我是用的pip install keras来安装的keras,但是没有keras按照这个安装最新的版本。这就是为什么我会做这样的事情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。因为它不是在以前的版本中。

SO, just clonethe kerasfrom their github, cdinto it, and run sudo python setup.py installwill solve this problem.

所以,只要clonekeras他们的github上cd到它,并运行sudo python setup.py install将解决这个问题。

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

请记住,如果您已经这样做了,则必须通过多次执行此操作pip install keras来确保清除keras已安装的所有版本,pip uninstall keras直到不keras存在为止,然后执行此操作sudo python setup.py install

回答by Ben J.

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

我从https://pypi.python.org/pypi/Keras/0.1.3查看了 tar.gz ,在 utils 文件夹中没有名为 data_utils.py 的文件。但是 github 确实包含此文件:https://github.com/fchollet/keras

回答by Anuj Gupta

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.

应该为你做这项工作。

回答by deepgradient

this might solve your problem.

这可能会解决您的问题。

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