使用导入 keras 时无法导入名称 'tf_utils'
Cannot import name 'tf_utils' when using importing keras
我正在使用 Oracle Linux 7.7,并且我使用 yum (epel repos) 安装了 python3.6。然后我安装 tensorflow 1.5(因为如果它更新版本我得到核心转储)和 keras。如果我导入 tensorflow,我什么也得不到。
但是当我导入keras时,我得到了
ImportError: cannot import name 'tf_utils'
这是完整的输出:
$ 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'
我之前使用 python 3.6 通过从源代码构建它并且 keras 工作正常但是因为我不能为 pyplot 安装 tkinter 我卸载它并改用 yum 中的那个。
好像是keras 2.3.0的问题,我用pip安装了keras 2.1.5,运行正常。
我遇到了同样的问题,但是通过 pip 升级了 Tensorflow 而不是降级 Keras,这解决了问题:)
使用 Python 3.6.4、Keras 2.3.1、Tensorflow 2.0
我正在使用 Oracle Linux 7.7,并且我使用 yum (epel repos) 安装了 python3.6。然后我安装 tensorflow 1.5(因为如果它更新版本我得到核心转储)和 keras。如果我导入 tensorflow,我什么也得不到。 但是当我导入keras时,我得到了
ImportError: cannot import name 'tf_utils'
这是完整的输出:
$ 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'
我之前使用 python 3.6 通过从源代码构建它并且 keras 工作正常但是因为我不能为 pyplot 安装 tkinter 我卸载它并改用 yum 中的那个。
好像是keras 2.3.0的问题,我用pip安装了keras 2.1.5,运行正常。
我遇到了同样的问题,但是通过 pip 升级了 Tensorflow 而不是降级 Keras,这解决了问题:)
使用 Python 3.6.4、Keras 2.3.1、Tensorflow 2.0