Skip to main content
 首页 » 编程设计

python之无法在 VScode 中调试 Python

2024年12月31日9sharpest

每当我尝试在 VScode(甚至 visual studio)中调试任何 python 代码时,我都会在它到达第一行代码之前遇到错误(或者看起来是这样)。大约 18 小时前,我能够在我的笔记本电脑和台式电脑上调试 VScode 和 Visual Studio,然后休息一下。大约 4 小时前,我在尝试运行调试时一直遇到错误。我可以通过 cmd.exe C:\Python\Python37-32\python.exe C:\Coding\Codecademy\Python\one.py 毫无问题地通过 python.exe 运行代码。

我已尝试卸载 VScode、Visual Studio 和 python,并删除了与任何 VScode 或 Visual Studio 相关的所有文件。然后我重新安装了 VScode 和 python 3.7,但错误仍然出现在终端中。即使使用简单的 print("Hello World") 也会发生这种情况。

我目前使用的是 Microsoft 的 Python 扩展,没有安装其他扩展。

错误代码如下:

Traceback (most recent call last): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_process_net_command.py", line 841, in process_net_command 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
Traceback (most recent call last): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_process_net_command.py", line 841, in process_net_command 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 411, in _on_run 
    self.process_command(cmd_id, int(args[1]), args[2]) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 426, in process_command 
    self.process_net_command(self.global_debugger_holder.global_dbg, cmd_id, seq, text) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_process_net_command.py", line 859, in process_net_command 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
Can't process net command: 501  1000000000      1.1     WINDOWS ID 
Traceback (most recent call last): 
Traceback (most recent call last): 
Traceback (most recent call last): 
Traceback (most recent call last): 
Exception in thread pydevd.Reader: 
Traceback (most recent call last): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_process_net_command.py", line 841, in process_net_command 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 411, in _on_run 
    self.process_command(cmd_id, int(args[1]), args[2]) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 426, in process_command 
    self.process_net_command(self.global_debugger_holder.global_dbg, cmd_id, seq, text) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_process_net_command.py", line 845, in process_net_command 
    traceback.print_exc() 
  File "C:\Python\Python37-32\lib\traceback.py", line 159, in print_exc 
    print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) 
  File "C:\Python\Python37-32\lib\traceback.py", line 101, in print_exception 
    print(line, file=file, end="") 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_io.py", line 30, in write 
    r.write(s) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1242, in write 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 413, in _on_run 
    traceback.print_exc() 
  File "C:\Python\Python37-32\lib\traceback.py", line 159, in print_exc 
    print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) 
  File "C:\Python\Python37-32\lib\traceback.py", line 101, in print_exception 
    print(line, file=file, end="") 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_io.py", line 30, in write 
    r.write(s) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1242, in write 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 321, in run 
    self._on_run() 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 418, in _on_run 
    traceback.print_exc() 
  File "C:\Python\Python37-32\lib\traceback.py", line 159, in print_exc 
    print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) 
  File "C:\Python\Python37-32\lib\traceback.py", line 101, in print_exception 
    print(line, file=file, end="") 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_io.py", line 30, in write 
    r.write(s) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1242, in write 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "C:\Python\Python37-32\lib\threading.py", line 917, in _bootstrap_inner 
    self.run() 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 324, in run 
    traceback.print_exc() 
  File "C:\Python\Python37-32\lib\traceback.py", line 159, in print_exc 
    print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) 
  File "C:\Python\Python37-32\lib\traceback.py", line 101, in print_exception 
    print(line, file=file, end="") 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_io.py", line 30, in write 
    r.write(s) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1242, in write 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
Unhandled exception in thread started by Unhandled exception in thread started by <bound method Thread._bootstrap of <ReaderThread(pydevd.Reader, started daemon 1916)>> 
 
Traceback (most recent call last): 
 
 
During handling of the above exception, another exception occurred: 
 
 
 
During handling of the above exception, another exception occurred: 
 
 
 
During handling of the above exception, another exception occurred: 
 
 
 
During handling of the above exception, another exception occurred: 
 
 
 
During handling of the above exception, another exception occurred: 
 
 
Traceback (most recent call last): 
 
Traceback (most recent call last): 
Exception in thread pydevd.CheckAliveThread: 
Traceback (most recent call last): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 321, in run 
    self._on_run() 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 185, in _on_run 
    if not self.py_db.has_threads_alive() and self.py_db.writer.empty(): 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 488, in empty 
    return self.cmdQueue.empty() 
AttributeError: 'Queue' object has no attribute 'empty' 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "C:\Python\Python37-32\lib\threading.py", line 917, in _bootstrap_inner 
    self.run() 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 324, in run 
    traceback.print_exc() 
  File "C:\Python\Python37-32\lib\traceback.py", line 159, in print_exc 
    print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) 
  File "C:\Python\Python37-32\lib\traceback.py", line 101, in print_exception 
    print(line, file=file, end="") 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_io.py", line 30, in write 
    r.write(s) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1242, in write 
    py_db.writer.add_command(cmd) 
  File "c:\Users\kyrus\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 448, in add_command 
    self.cmdQueue.put(cmd) 
AttributeError: 'Queue' object has no attribute 'put' 
Unhandled exception in thread started by Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace object at 0x0405B7F0> 
 
Traceback (most recent call last): 
 
 
During handling of the above exception, another exception occurred: 
 
 
 
During handling of the above exception, another exception occurred: 
 
 
Unhandled exception in thread started by Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace object at 0x04096B10> 
 
Traceback (most recent call last): 

更新: 问题仍然存在,但我注意到另一个区域似乎抛出关于 python 的类似错误(与“队列”对象相关)。每当我尝试安装 linter 时,它都会在终端中抛出以下错误:

PS C:\Coding\Codecademy\Python> & C:/Python/Python37/python.exe -m pip install -U pep8 --user 
Traceback (most recent call last): 
  File "C:\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main 
    "__main__", mod_spec) 
  File "C:\Python\Python37\lib\runpy.py", line 85, in _run_code 
    exec(code, run_globals) 
  File "C:\Python\Python37\lib\site-packages\pip\__main__.py", line 16, in <module> 
    from pip._internal import main as _main  # noqa 
  File "C:\Python\Python37\lib\site-packages\pip\_internal\__init__.py", line 20, in <module> 
    from pip._vendor.urllib3.exceptions import DependencyWarning 
  File "C:\Python\Python37\lib\site-packages\pip\_vendor\urllib3\__init__.py", line 8, in <module> 
    from .connectionpool import ( 
  File "C:\Python\Python37\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 58, in <module> 
    class ConnectionPool(object): 
  File "C:\Python\Python37\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 65, in ConnectionPool 
    QueueCls = queue.LifoQueue 
AttributeError: module 'queue' has no attribute 'LifoQueue' 
PS C:\Coding\Codecademy\Python> 

请您参考如下方法:

尝试检查你的 python 版本我在 VScode 中尝试运行我的 python3 代码时遇到了类似的错误。尝试在 vscode 中更改 python 版本。