简体   繁体   English

使用 VS Code 调试 python 文件。 断点抛出异常,断点被忽略

[英]Using VS Code to debug python files. Exception thrown on breakpoint and breakpoint is ignored

Tried with multiple different python files.尝试使用多个不同的 python 文件。 Every time I try to use the debugger in vs code and set breakpoints the breakpoint gets ignored and exception gets raised and the script continues on.每次我尝试在 vs 代码中使用调试器并设置断点时,都会忽略断点并引发异常并且脚本继续运行。 I've been googling and tinkering for over 2 hours and can't seem to figure out what's going on here.我一直在谷歌搜索和修补超过 2 小时,似乎无法弄清楚这里发生了什么。 Tried rebooting PC, running vs code as admin, uninstall/reinstall the python extension for vs code.尝试重新启动 PC,以管理员身份运行 vs code,卸载/重新安装 vs code 的 python 扩展。 Tried to dig into the files mentioned in the traceback and pinpointed the function that seems to be raising the exception but I can't figure out where it's being called from or why it's raising the exception.试图深入研究回溯中提到的文件并查明 function 似乎引发了异常,但我无法弄清楚它是从哪里调用的或为什么会引发异常。 I'm still new-ish to Python.我对 Python 还是很陌生。 Debugging works properly on my laptop but for whatever reason my desktop is having this issue.调试在我的笔记本电脑上正常工作,但无论出于何种原因,我的桌面都出现了这个问题。

Traceback (most recent call last):
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py", line 529, in _original_file_to_client
    return cache[filename]
KeyError: 'c:\\users\\joel\\local settings\\application data\\programs\\python\\python37-32\\lib\\runpy.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 330, in _on_run
    self.process_net_command_json(self.py_db, json_contents)
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_process_net_command_json.py", line 190, in process_net_command_json    
    cmd = on_request(py_db, request)
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_process_net_command_json.py", line 771, in on_stacktrace_request       
    self.api.request_stack(py_db, request.seq, thread_id, fmt=fmt, start_frame=start_frame, levels=levels)
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_api.py", line 214, in request_stack
    if internal_get_thread_stack.can_be_executed_by(get_current_thread_id(threading.current_thread())):
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 661, in can_be_executed_by
    py_db, self.seq, self.thread_id, frame, self._fmt, must_be_suspended=not timed_out, start_frame=self._start_frame, levels=self._levels)
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_net_command_factory_json.py", line 213, in make_get_thread_stack_message
    py_db, frames_list
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_net_command_factory_xml.py", line 175, in _iter_visible_frames_info    
    new_filename_in_utf8, applied_mapping = pydevd_file_utils.norm_file_to_client(filename_in_utf8)
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py", line 531, in _original_file_to_client
    translated = _path_to_expected_str(get_path_with_real_case(_AbsFile(filename)))
  File "c:\Users\Joel\.vscode\extensions\ms-python.python-2020.7.96456\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\Joel\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd_file_utils.py", line 184, in _resolve_listing
    dir_contents = cache[resolved_lower] = os.listdir(resolved)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\Joel\\Local Settings' 

So I get this traceback every time a breakpoint is hit.所以每次遇到断点时我都会得到这个回溯。 Taking a peek at the "_original_file_to_client" function in "pydevd_file_utils.py" we get this:查看“pydevd_file_utils.py”中的“_original_file_to_client”function,我们得到:

def _original_file_to_client(filename, cache={}):
    try:
        return cache[filename]
    except KeyError:
        translated = _path_to_expected_str(get_path_with_real_case(_AbsFile(filename)))
        cache[filename] = (translated, False)
    return cache[filename]

I wasn't able to figure out where this function was being called from or what the expected output was supposed to be.我无法弄清楚这个 function 是从哪里调用的,或者预期的 output 应该是什么。 Any help with this would be greatly appreciated!对此的任何帮助将不胜感激!

Edit: Forgot to mention I'm using Windows 10 if it wasn't obvious from the trace编辑:忘了提我正在使用 Windows 10 如果从跟踪中不明显的话

This is a similar question. 是一个类似的问题。 The spaces in the filename cause this problem: "Local Settings", "application data"文件名中的空格导致此问题:“本地设置”、“应用程序数据”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM