【已解决cannot import name ‘OrderedDict‘ from ‘typing‘】

在import tensorflow as tf 时报错no mould tensorflow,自然而然想到pip一下,但是pip一直显示成功,并且不会报任何错

1.报错:导入import tensorflow as tf时,会出现cannot import name ‘Callable‘ from ‘typing_extensions‘。

由于我下载的是python3.7版本,tensorflow可能需要下载补丁包,故在网上查询解决方案:

pip install typing_extensions

在下载后,将该目录下的function_type.py中的

from typing import Any,Callable,Dict, Mapping, Optional, Sequence, Tuple

改为

from typing_extensions import Any,Callable,Dict, Mapping, Optional, Sequence, Tuple

此时依旧会报错cannot import name ‘Callable‘ from ‘typing_extensions‘
说明typing_extensions里面没有Callable,而typing中没有OrderedDict。

2.交叉组合一下把两个包一起导入

只能选择“各取所需”,组合一下试试

from typing import Any,Callable,Dict, Mapping, Optional, Sequence, Tuple
from typing_extensions import OrderedDict

这里前提是已经pip install typing_extensions了,也就是两个:typing_extensions和typing都存在的情况下,改写。

再次运行tensorflow则不会报错

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2023年8月17日
下一篇 2023年8月17日

相关推荐