【问题标题】:tensorflow_hub import error (most likely due to a circular import) on Mac M1 and Jupyter NotebookMac M1 和 Jupyter Notebook 上的 tensorflow_hub 导入错误(很可能是由于循环导入)
【发布时间】:2021-12-26 09:30:15
【问题描述】:

环境是 Mac M1 和带有 python3.8 的 miniforge Conda。我已经完成了以下命令来安装 tensorflow 和 tensorflow_hub:

conda install -c apple tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal

# tried all the conda commands here (https://anaconda.org/conda-forge/tensorflow-hub) and the following
pip install tensorflow_hub

在 Jupyter Notebook 上导入 tensorflow_hub 时出现以下错误:

cannot import name 'LinearSDCA' from partially initialized module 
'tensorflow_estimator.python.estimator.canned.linear' (most likely due to a circular import)
 (/myenv/lib/python3.8/site-packages/tensorflow_estimator/python/estimator/canned/linear.py)

使用终端导入tensorflow_hub时,报错信息为:

E tensorflow/core/lib/monitoring/collection_registry.cc:77] Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers
...Traceback...
self._metric = self._metric_methods[self._label_length].create(*args)
tensorflow.python.framework.errors_impl.AlreadyExistsError: Another metric with the same name already exists.

目前我的tensorflow_estimator的版本是2.6.0,tensorflow_hub的版本是0.12.0。我尝试更改 tensorflow_estimator 的版本。但是,我能够安装且没有错误的唯一 tensorflow-macos 版本是 2.6.0,它需要 tensorflow_estimator 2.6.0。感谢您的时间和您可以提供的任何帮助。

【问题讨论】:

    标签: python tensorflow jupyter-notebook conda tensorflow-hub


    【解决方案1】:

    Is keras 2.7 installed? 如果是这样,请通过pip install -U keras==2.6.0 降级,因为它与 TF 2.6 不兼容。 TF 2.6.2 修复了某些依赖项的上限,以便该版本可以开箱即用。

    【讨论】:

    • 您好 WGierke,感谢您的回复。我将 keras 降级到 2.6.0,但在 Jupyter Notebook 上仍然出现同样的错误。在终端上导入 tensorflow_hub 时出现错误AttributeError: module 'tensorflow' has no attribute 'flags'。此外,tensorflow-macos==2.6.2 没有匹配的分布。
    • 您能否通过将pip freeze 的结果上传到例如pastebin.com?当您尝试导入 tensorflow_hub 等时,您是否也有该错误发生的确切位置的堆栈跟踪?
    猜你喜欢
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2020-12-18
    • 2021-08-24
    相关资源
    最近更新 更多