简体   繁体   中英

tensorflow_hub can't find 'keras.api' module

I am using Anaconda Spyder5 with python 3.8 My tensorflow is working fine, I can train and predict NNs. But when I try to import 'tensorflow_hub' I get the following error:

import tensorflow as tf
print("TF Version: ", tf.__version__)

import tensorflow_hub as hub
print("TF-Hub version: ", hub.__version__)

The generated error:

TF Version:  2.6.0
Traceback (most recent call last):

  File "C:\Users\aurelio\AppData\Local\Temp/ipykernel_9332/220386776.py", line 4, in <module>
    import tensorflow_hub as hub

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\site-packages\tensorflow_hub\__init__.py", line 29, in <module>
    from tensorflow_hub.estimator import LatestModuleExporter

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\site-packages\tensorflow_hub\estimator.py", line 64, in <module>
    class LatestModuleExporter(tf_v1.estimator.Exporter):

  File "C:\Users\aurelio\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\util\lazy_loader.py", line 62, in __getattr__
    module = self._load()

  File "C:\Users\aurelio\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\util\lazy_loader.py", line 45, in _load
    module = importlib.import_module(self.__name__)

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\site-packages\tensorflow_estimator\__init__.py", line 10, in <module>
    from tensorflow_estimator._api.v1 import estimator

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 10, in <module>
    from tensorflow_estimator._api.v1.estimator import experimental

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 10, in <module>
    from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\site-packages\tensorflow_estimator\python\estimator\canned\dnn.py", line 29, in <module>
    from tensorflow_estimator.python.estimator.canned import optimizers

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\site-packages\tensorflow_estimator\python\estimator\canned\optimizers.py", line 34, in <module>
    'Adagrad': tf.keras.optimizers.Adagrad,

  File "C:\Users\aurelio\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\util\lazy_loader.py", line 62, in __getattr__
    module = self._load()

  File "C:\Users\aurelio\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\util\lazy_loader.py", line 45, in _load
    module = importlib.import_module(self.__name__)

  File "C:\ProgramData\Anaconda3\envs\tenso\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

ModuleNotFoundError: No module named 'keras.api'

What I have tried:

  1. Uninstall and install all tensorflow and keras packages
  2. Upgrade all packages

Any help is very very welcomed!

Thank you

We're currently seeing issues with TF 2.6.0 installing tensorflow-estimator 2.7.0. If you've installed tensorflow-estimator 2.7.0, please try downgrading it to 2.6.0. If you don't have version 2.7.0, please provide a more complete list of which libraries and versions you have installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM