环境
Python 3.8.0a2
Pip 18.1
动作
Pip升级pip 22.0.4
pip install --upgrade pip
BUG
升级后使用pip命令报错:
File “C:\opt\client\python3\Python38\lib\site-packages\pip_vendor\rich\console.py”, line 36, in
from typing import Literal, Protocol, runtime_checkable
ImportError: cannot import name ‘Literal’ from ‘typing’ (C:\opt\client\python3\Python38\lib\typing.py)
解决方法
参考:https://stackoverflow.com/questions/61206437/importerror-cannot-import-name-literal-from-typing
1.因为pip命令不可用,使用easy_install安装typing_extensions
easy_install typing_extensions
2.修改pip代码
$PYTHON_HOME\lib\site-packages\pip_vendor\rich目录下:
console.py
if sys.version_info >= (3, 8):
from typing import Literal, Protocol, runtime_checkable
else:
from pip._vendor.typing_extensions import (
Literal,
Protocol