Python 使用导入 keras 时无法导入名称“tf_utils”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/57985406/
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
Cannot import name 'tf_utils' when using importing keras
提问by Christophorus Reyhan
I'm using Oracle Linux 7.7, and I installed python3.6 using yum (epel repos). Then I install tensorflow 1.5(since if it goes newer ver I got core dumped) and keras. If I'm importing tensorflow, I got nothing. But when I import keras, I got
我使用的是 Oracle Linux 7.7,我使用 yum (epel repos) 安装了 python3.6。然后我安装 tensorflow 1.5(因为如果它更新了,我得到了核心转储)和 keras。如果我要导入 tensorflow,我什么也得不到。但是当我导入 keras 时,我得到了
ImportError: cannot import name 'tf_utils'
Here's the full output:
这是完整的输出:
$ python
Python 3.6.8 (default, Aug 7 2019, 08:02:28)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39.0.1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/__init__.py", line 3, in <module>
from . import utils
File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/utils/__init__.py", line 6, in <module>
from . import conv_utils
File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in <module>
from .. import backend as K
File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/backend/__init__.py", line 1, in <module>
from .load_backend import epsilon
File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/backend/load_backend.py", line 90, in <module>
from .tensorflow_backend import *
File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 13, in <module>
from tensorflow.python.keras.utils import tf_utils
ImportError: cannot import name 'tf_utils'
I was using python 3.6 by building it from source before and keras worked fine but since I can't install tkinter for pyplot I uninstall it and using the one from yum instead.
我之前通过从源代码构建它来使用 python 3.6,并且 keras 工作正常,但是由于我无法为 pyplot 安装 tkinter,我将其卸载并使用 yum 中的那个。
回答by Christophorus Reyhan
Seems like it was a problem with keras 2.3.0, I installed keras 2.1.5 using pip and it works fine.
似乎是 keras 2.3.0 的问题,我使用 pip 安装了 keras 2.1.5 并且工作正常。
回答by FantasticManWhale
I had the same problem, but upgraded Tensorflow via pip rather than downgrading Keras and this solved the problem :)
我遇到了同样的问题,但是通过 pip 升级了 Tensorflow 而不是降级 Keras,这解决了问题:)
Using Python 3.6.4, Keras 2.3.1, Tensorflow 2.0
使用 Python 3.6.4、Keras 2.3.1、Tensorflow 2.0