tensorflow导入keras出错问题

在升级tensorflow到2.10.1过程中,出现keras导入时出错问题,在网上进行了几个小时的搜索,没有找到好的解决方案。大体的解决思路是tensorflow与keras的版本不兼容。实际问题解决后,确实是这个原因。在网上查找的tensorflow对应的版本都比较低,这里可以使用的版本是:tensorflow为2.10.1,keras的版本为2.10.0。先安装keras, 再安装tensorflow。

pip install keras=2.10.0

pip install tensorflow==2.10.1

安装的结果:

Installing collected packages: tensorflow-estimator, tensorboard-data-server, google-auth-oauthlib, tensorboard, tensorflow
  Attempting uninstall: tensorflow-estimator
    WARNING: Ignoring invalid distribution -rotobuf (c:\users\he\.conda\envs\tf2\lib\site-packages)
    Found existing installation: tensorflow-estimator 2.11.0
    Uninstalling tensorflow-estimator-2.11.0:
      Successfully uninstalled tensorflow-estimator-2.11.0
  Attempting uninstall: tensorboard-data-server
    Found existing installation: tensorboard-data-server 0.7.0
    Uninstalling tensorboard-data-server-0.7.0:
      Successfully uninstalled tensorboard-data-server-0.7.0
  Attempting uninstall: google-auth-oauthlib
    Found existing installation: google-auth-oauthlib 1.0.0
    Uninstalling google-auth-oauthlib-1.0.0:
      Successfully uninstalled google-auth-oauthlib-1.0.0
  Attempting uninstall: tensorboard
    Found existing installation: tensorboard 2.13.0
    Uninstalling tensorboard-2.13.0:
      Successfully uninstalled tensorboard-2.13.0
  Attempting uninstall: tensorflow
    Found existing installation: tensorflow 2.11.1
    Uninstalling tensorflow-2.11.1:
      Successfully uninstalled tensorflow-2.11.1


Successfully installed google-auth-oauthlib-0.4.6 tensorboard-2.11.2 tensorboard-data-server-0.6.1 tensorflow-2.10.1 tensorflow-estimator-2.10.0