在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则不会报错

查看原文