python 和模块未找到错误:没有名为'tensorflow.keras'的模块

4szc88ey  于 2023-01-01  发布在  Python
关注(0)|答案(1)|浏览(307)

我已经安装了带有Anaconda的TensorFlow,但它显示了一个错误。
我有以下版本:

Python                    3.9.13
keras                     2.11.0
tensorflow                2.11.0
tensorflow-estimator      2.11.0
tensorflow-gpu            2.10.1
tensorboard               2.11.0

这是我得到的错误:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow-gpu 2.10.1 requires keras<2.11,>=2.10.0, but you have keras 2.11.0 which is incompatible.
tensorflow-gpu 2.10.1 requires tensorboard<2.11,>=2.10, but you have tensorboard 2.11.0 which is incompatible.
tensorflow-gpu 2.10.1 requires tensorflow-estimator<2.11,>=2.10.0, but you have tensorflow-estimator 2.11.0 which is incompatible.

此外,当我运行

from tensorflow.keras.layers import TextVectorization

这是错误:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_6684\2805265792.py in <module>
----> 1 from tensorflow.keras.layers import TextVectorization

ModuleNotFoundError: No module named 'tensorflow.keras'

我尝试了以下方法:

pip install --user --upgrade tensorflow
pip install keras==2.11
pip install tensorflow-estimator==2.11
pip install tensorboard==2.11

但都不管用。

j0pj023g

j0pj023g1#

关于第一个错误,我认为你只需要安装兼容的版本:

pip install keras==2.10.0 tensorboard==2.10 tensorflow-estimator==2.10.0

关于第二个错误,您是否尝试过:

from keras.layers import TextVectorization

而不是使用tensorflow.keras
(Of当然你必须先用pip install keras安装keras)

相关问题