首页 > 解决方案 > VSCode 调试器 FileNotFoundError

问题描述

我目前有一些 .py 和 .ipynb 文件存储在 Google Drive (G:) 上,可以在我的设备上访问。将 .ipynb 文件转换为 .py 然后在 VSCode 中运行调试器时,有时会遇到以下问题:

Microsoft Windows [Version 10.0.19043.1052]
(c) Microsoft Corporation. All rights reserved.

G:\My Drive\Code & Programming>C:/Users/Admin/Anaconda3/Scripts/activate

(base) G:\My Drive\Code & Programming>conda activate base

(base) G:\My Drive\Code & Programming> cmd /C "C:\Users\Admin\Anaconda3\python.exe c:\Users\Admin\.vscode\extensions\ms-python.python-2021.5.926500501\pythonFiles\lib\python\debugpy\launcher 58376 -- "g:\My Drive\<dir1>\test.py" "
pydev debugger: critical: unable to get real case for file. Details:
filename: g:\
drive: G:\
parts: ['']
(please create a ticket in the tracker to address this).
Traceback (most recent call last):
  File "c:\Users\Admin\.vscode\extensions\ms-python.python-2021.5.926500501\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\Admin\.vscode\extensions\ms-python.python-2021.5.926500501\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py", line 192, in _resolve_listing    
    raise FileNotFoundError('Unable to find: %s in %s' % (
FileNotFoundError: Unable to find:  in G:\

During handling of the above exception, another exception occurred:

但是,如果我将 .py 文件保存到不同的 G:\ 目录,调试器将运行:

Microsoft Windows [Version 10.0.19043.1052]
(c) Microsoft Corporation. All rights reserved.

G:\My Drive\Code & Programming>C:/Users/Admin/Anaconda3/Scripts/activate

(base) G:\My Drive\Code & Programming>conda activate base

(base) G:\My Drive\Code & Programming> cmd /C "C:\Users\Admin\Anaconda3\python.exe c:\Users\Admin\.vscode\extensions\ms-python.python-2021.5.926500501\pythonFiles\lib\python\debugpy\launcher 53852 -- "g:\My Drive\<dir2>\test.py" "

该错误似乎并没有真正提供太多信息,说明为什么 dir1 中的 test.py 文件失败,但 dir2 没有。

谢谢!

标签: pythonvisual-studio-codejupyter

解决方案


Visual Studio 与其他广泛使用的 IDE 一起,将许多目录位置作为命令行命令读取。

出于这个原因,删除命令行中使用的特殊字符(例如-用于标志或 分隔命令的 s)非常重要。

正如您在回复评论中所述,删除其中一个目录的空格解决了该问题。

没有全面的指南,因为它是基于系统的 IDE/系统,但是这个 Winodws 指南应该是一个好的开始。

祝一切顺利!


推荐阅读