VSCode调试python3.7时报错:ImportError: cannot import name ‘Literal‘ from ‘typing‘ (c:\Users\admin\AppData

1. 环境

系统:Win10
python:3.7.0
VSCode:1.94.2
VSCode拓展【Python Debugger】:v2024.12.0

2. 报错现象

在这里插入图片描述
任意python脚本(甚至空文件),点【运行python文件】没有问题,点【Python调试程序:调试Python文件】就会直接出现如下报错:

ImportError: cannot import name 'Literal' from 'typing' (c:\Users\admin\AppData\Local\Programs\Python\Python37\lib\typing.py)

3. 原因

VSCode拓展【Python Debugger】的最新版本不支持 python3.7。
见【Python Debugger】的说明:

Older versions of the Python Debugger extension are available for debugging Python projects that use outdated Python versions like Python 2.7 and Python 3.6. However, it’s important to note that our team is no longer maintaining these extension versions. We strongly advise you to update your project to a supported Python version if possible.

Python Debugger扩展的旧版本可用于调试使用过时Python版本(如Python 2.7和Python 3.6)的Python项目。然而,需要注意的是,我们的团队不再维护这些扩展版本。如果可能,我们强烈建议您将项目更新为受支持的Python版本。

You can reference the table below to find the most recent Python Debugger extension version that offers debugging support for projects using deprecated Python versions, as well as the debugpy version that is shipped in each extension version.

你可以参考下表来找到最新的Python调试器扩展版本,它为使用废弃Python版本的项目提供调试支持,以及每个扩展版本中附带的debugpy版本。

Python versionLatest supported Python Debugger extension versiondebugpy version
2.7, >= 3.52023.1.XXX1.5.1
>= 3.72024.0.XXX1.7.0
>>= 3.82024.2.XXX1.8.1

4. 解决方案

将VSCode拓展【Python Debugger】更改到指定版本 v2024.10.0,并取消自动更新。
重启VSCode,完美解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值