解决:ImportError: cannot import name ‘Literal’ from ‘typing’ (PYTHON_HOME\lib\typing.py

环境
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,
runtime_checkable,
) # pragma: no cover
改:
try:
from typing import Literal
except ImportError:
from pip._vendor.typing_extensions import (
Literal,
Protocol,
runtime_checkable,
) # pragma: no cover

emoji.py文件
align.py文件
box.py文件
$PYTHON_HOME \lib\site-packages\pip_vendor\platformdirs\api.py文件
live_render.py文件
if sys.version_info >= (3, 8):
from typing import Literal
else:
from pip._vendor.typing_extensions import Literal # pragma: no cover
改:
try:
from typing import Literal
except ImportError:
from pip._vendor.typing_extensions import Literal # pragma: no cover

_ratio.py文件改
try:
from typing import Literal
except ImportError:
from pip._vendor.typing_extensions import Literal, Protocol # pragma: no cover

OKK
在这里插入图片描述

你可能感兴趣的:(python,python,pycharm,开发语言)