首页 > 解决方案 > TensorFlow 在导入期间失败:“ImportError: cannot import name 'mirrored_strategy_with_two_gpus_no_merge_call'”

问题描述

我在 Windows 10 笔记本电脑上使用 Python 3.8.10 版从 Anaconda 虚拟环境运行 TensorFlow 2.3.0 版。venv 已设置并运行良好,直到 IDE 在导入时开始抛出以下错误:

2021-08-04 19:12:57.977474: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2021-08-04 19:12:57.979433: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):

  File "C:\Users\zachary.holden\Documents\Python-Scripts\SpeakerIdentification\SpeakerIdentification.py", line 4, in <module>
    import tensorflow as tf

  File "C:\Users\zachary.holden\AppData\Roaming\Python\Python38\site-packages\tensorflow\__init__.py", line 49, in <module>
    from ._api.v2 import __internal__

  File "C:\Users\zachary.holden\AppData\Roaming\Python\Python38\site-packages\tensorflow\_api\v2\__internal__\__init__.py", line 13, in <module>
    from . import distribute

  File "C:\Users\zachary.holden\AppData\Roaming\Python\Python38\site-packages\tensorflow\_api\v2\__internal__\distribute\__init__.py", line 10, in <module>
    from . import combinations

  File "C:\Users\zachary.holden\AppData\Roaming\Python\Python38\site-packages\tensorflow\_api\v2\__internal__\distribute\combinations\__init__.py", line 20, in <module>
    from tensorflow.python.distribute.strategy_combinations import mirrored_strategy_with_two_gpus_no_merge_call

ImportError: cannot import name 'mirrored_strategy_with_two_gpus_no_merge_call' from 'tensorflow.python.distribute.strategy_combinations'

我尝试完全卸载并重新安装 Anaconda3,但同样的错误仍然存​​在。我的计算机上没有 GPU 设置,尽管这在过去似乎不是问题。这是版本兼容性问题吗?

此外,我尝试了这个问题中提出的解决方案,看起来很相似,但问题仍然存在。

标签: pythonpython-3.xtensorflowtensorflow2.0

解决方案


推荐阅读