我在 Windows 10 上全新安装了 Python 3.7-32。
我想尝试 Protocols python 方法,接下来我会这样做:
文件 test_protocols.py 只有一行:
from typing import Protocol
then:
>python test_protocols.py
我有下一条错误消息需要解释:
Traceback (most recent call last):
File "test_protocols.py", line 1, in <module>
from typing import Protocol
ImportError: cannot import name 'Protocol' from 'typing' (C:\Programing\Python\Python37-32\lib\typing.py)
我做错了什么?
也许我读错了 PEP-0544,但从我的角度来看,我按照记录的方式做了同样的事情。
如果打字时不存在
pip install typing_extensions
from typing_extensions import Protocol
根据操作系统和 Python 版本,协议类可能位于打字模块内或打字扩展中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)