Cannot import name 'tf_utils' when using importing keras

元气小坏坏 提交于 2020-03-09 14:22:11

问题


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

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.


回答1:


Seems like it was a problem with keras 2.3.0, I installed keras 2.1.5 using pip and it works fine.




回答2:


I had the same problem, but upgraded Tensorflow via pip rather than downgrading Keras and this solved the problem :)

Using Python 3.6.4, Keras 2.3.1, Tensorflow 2.0



来源:https://stackoverflow.com/questions/57985406/cannot-import-name-tf-utils-when-using-importing-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!