无法导入tensorflow,并出现错误“没有名为'tensorflow.python.distribute.load_context'的模块”

问题描述 投票:0回答:1

我正在尝试使用以下命令导入张量流:

import tensorflow as tf

但是,我不断收到以下错误消息:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 import tensorflow as tf

File c:\Users\Lenovo\.pyenv\pyenv-win\versions\3.11.0\Lib\site-packages\tensorflow\__init__.py:45
     42 from tensorflow.python import tf2 as _tf2
     43 _tf2.enable()
---> 45 from tensorflow._api.v2 import __internal__
     46 from tensorflow._api.v2 import __operators__
     47 from tensorflow._api.v2 import audio

File c:\Users\Lenovo\.pyenv\pyenv-win\versions\3.11.0\Lib\site-packages\tensorflow\_api\v2\__internal__\__init__.py:27
     25 from tensorflow._api.v2.__internal__ import train
     26 from tensorflow._api.v2.__internal__ import types
---> 27 from tensorflow.python.distribute.load_context import load_context # line: 49
     28 from tensorflow.python.eager.backprop import record_gradient # line: 160
     29 from tensorflow.python.eager.context import is_tfrt_enabled # line: 124

ModuleNotFoundError: No module named 'tensorflow.python.distribute.load_context'

我的python版本是3.11.0,tensorflow版本是2.15.0。

有人可以帮我吗?

python-3.x tensorflow python-import tensorflow2.0
1个回答
0
投票

尝试安装 anaconda 并使用 Anaconda 提示符创建环境。 创建环境后,使用以下命令安装库: pip install tensorflow 并从环境中运行您的程序。

© www.soinside.com 2019 - 2024. All rights reserved.