【问题标题】:VSCode Debug Mode sometimes does not work due to a PyDev FileNotFoundError由于 PyDev FileNotFoundError,VSCode 调试模式有时无法工作
【发布时间】:2021-05-12 20:44:01
【问题描述】:

老实说,我不知道我在看什么。

当我开始调试时,我在这个 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 _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: ''
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 _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: ''

我已经在错误中提到的tracker 上发布了一张票,但老实说,我不知道 PyDev 是什么,或者是否有办法重新安装它并解决问题。

有什么解决方法吗?我真的不知道我在问什么纯粹是因为这对我来说太陌生了,但这只是那些似乎没有任何真正原因自发发生的错误之一。

【问题讨论】:

  • 没有承诺,但试试这个(类似的事情发生在我身上,我能够用以下方法解决它)。你在为你的 Python 调试使用配置吗?在./vscode/launch.json 下,您将拥有工作区的现有调试配置。如果没有,请设置一个。直到几天前,我的program 使用./main.py 都没有问题(看来您使用了bot),但更新后出现错误。尝试使用 ${workspaceFolder}\\ 以及正确的文件名和位置将其更改为 "program": "${workspaceFolder}\\bot.py",然后看看你的情况。如果这没有帮助,请粘贴您的launch.json
  • @Woodsy 我不知道如何解决这个问题。非常感谢。
  • 很高兴听到这个消息!如果您能在下面接受我的回答,那就太好了:)

标签: python python-3.x visual-studio-code pydev


【解决方案1】:

答案:

./.vscode/launch.json 中的"program": "bot" 更改为"program": "${workspaceFolder}\\bot.py"

对于大多数人来说,文件名不会是 bot,而是 mainscript 或任何你称之为 Python 脚本文件的名称。所以你会使用"${workspaceFolder}\\main.py"等。

背景:

在最近更新的 pydev 调试器中,我假设他们已经更新了文件位置的解析方式。

你使用的file name(VS Code 称之为program)是bot,这个语法不再有效。./bot 以前也有效,但会抛出一个稍微不同的错误.我不确定此更改是错误还是预期更改。

您在 VS Code 中的工作区的 Python 调试配置位于 {workspaceFolder}/.vscode/launch.json 下(如果您还没有 launch.json,请创建一个)。

您必须使用 {workspaceFolder}\\ 以及正确的文件名和位置将 "program": "bot" 更改为 "program": "${workspaceFolder}\\bot.py"

这假设您从其根目录启动您的工作区。您可以通过打开集成终端时的起始目录来判断这一点。

【讨论】:

    【解决方案2】:

    这是出现此类错误的原因以及修复它的更好方法

    发生错误是因为python调试器从当前打开的文件夹执行终端中的文件(默认)
    但是您可以更改此行为,以在文​​件目录中使用执行:

    • 进入vscode设置(或使用快捷键:ctrl+comma
    • 然后在设置中搜索这个@ext:ms-python.python execute
    • 您会看到设置“在文件目录中执行”
    • 然后选中复选框,在文件目录而不是当前打开的文件夹中执行代码
    • 返回您的代码并重新运行(即单击调试器运行按钮)

    当您知道文件位于正确的位置并且指向正确的方向时,这将消除 FileNotFoundError。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 2022-12-17
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多