问题描述
老实说,我不知道我在看什么。
当我开始调试时,我在这个 VSCode 项目(一个 discord 机器人)中的调试配置突然出现错误。正常运行程序的时候不会这样,其他项目调试好像没问题。
大约 50% 的情况下,尽管出现错误并且调试正常,但它最终会连接到 discord,但其他时候程序会挂起并拒绝连接到 discord。
这是错误文本,对于转储这么多代码,我深表歉意,但我不知道其中是否有任何意义:
'c:\Users\Lucas\.vscode\extensions\ms-python.python-2021.5.829140558\pythonFiles\lib\python\debugpy\launcher' '51717' '--' 'bot/bot.py'
pydev debugger: critical: unable to get real case for file. Details:
filename: bot
drive:
parts: ['bot']
(please create a ticket in the tracker to address this).
Traceback (most recent call last):
File "c:\Users\Lucas\.vscode\extensions\ms-python.python-2021.5.829140558\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py",line 221,in _get_path_with_real_case
return _resolve_listing(drive,iter(parts))
File "c:\Users\Lucas\.vscode\extensions\ms-python.python-2021.5.829140558\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py",line 184,in _resolve_listing
dir_contents = cache[resolved_lower] = os.listdir(resolved)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "c:\Users\Lucas\.vscode\extensions\ms-python.python-2021.5.829140558\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py",line 226,in _resolve_listing
dir_contents = cache[resolved_lower] = os.listdir(resolved)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''
pydev debugger: critical: unable to get real case for file. Details:
filename: bot
drive:
parts: ['bot']
(please create a ticket in the tracker to address this).
Traceback (most recent call last):
File "c:\Users\Lucas\.vscode\extensions\ms-python.python-2021.5.829140558\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py",in _resolve_listing
dir_contents = cache[resolved_lower] = os.listdir(resolved)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''
我已经在错误中提到的 tracker 上发布了一张票,但老实说我不知道 PyDev 是什么,或者是否有办法甚至只是重新安装它并解决问题。
有什么解决方法吗?我真的不知道我在问什么纯粹是因为这对我来说太陌生了,但这只是那些似乎没有任何真正原因的自发发生的错误之一。
解决方法
答案:
将 "program": "bot"
中的 "program": "${workspaceFolder}\\bot.py"
更改为 ./.vscode/launch.json
。
对于大多数人来说,文件名不会是 bot
,而是 main
或 script
或任何您称之为 Python 脚本文件的名称。所以你会使用 "${workspaceFolder}\\main.py"
等。
背景:
在最近更新的 pydev 调试器中,我假设他们已经更新了文件位置的解析方式。
您使用的 file name
(VS Code 称之为 program
)是 bot
,并且此语法不再有效。同样曾经有效的./bot
将不再有效工作,但会抛出一个稍微不同的错误。我不确定此更改是错误还是有意更改。
VS Code 中工作区的 Python 调试配置位于 {workspaceFolder}/.vscode/launch.json
下(如果您还没有 launch.json
,请创建一个)。
您必须使用 "program": "bot"
以及正确的文件名和位置将 "program": "${workspaceFolder}\\bot.py"
更改为 {workspaceFolder}\\
。
这假设您是从其根目录启动工作区。可以通过打开集成终端时的起始目录来判断。