由于PyDevFileNotFoundError,VSCode调试模式有时不起作用
老实说,我不知道我在看什么。
当我开始调试时,我在这个 VSCode 项目(一个 Discord 机器人)中的调试配置突然出现错误。正常运行程序的时候是不会这样的,其他项目调试好像还可以。
大约 50% 的时间,尽管出现错误并且调试正常,它最终会连接到 Discord,但其他时候程序会挂起并拒绝连接到 Discord。
这是错误文本,对于转储这么多代码,我深表歉意,但我不知道其中是否有任何重要意义:
'c:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpylauncher' '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:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpy_vendoredpydevdpydevd_file_utils.py", line 221, in _get_path_with_real_case
return _resolve_listing(drive, iter(parts))
File "c:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpy_vendoredpydevdpydevd_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:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpy_vendoredpydevdpydevd_file_utils.py", line 226, in _get_path_with_real_case
return _resolve_listing(drive, iter(parts))
File "c:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpy_vendoredpydevdpydevd_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: ''
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:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpy_vendoredpydevdpydevd_file_utils.py", line 221, in _get_path_with_real_case
return _resolve_listing(drive, iter(parts))
File "c:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpy_vendoredpydevdpydevd_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:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpy_vendoredpydevdpydevd_file_utils.py", line 226, in _get_path_with_real_case
return _resolve_listing(drive, iter(parts))
File "c:UsersLucas.vscodeextensionsms-python.python-2021.5.829140558pythonFileslibpythondebugpy_vendoredpydevdpydevd_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: ''
我已经在错误中提到的跟踪器上张贴了一张票,但老实说,我不知道 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}正确的文件名和位置。
这假设您是从其根目录启动工作区。您可以通过打开集成终端时的起始目录来判断这一点。