无法在VScode中调试Python

4
每当我尝试在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相关的类似错误(涉及“Queue”对象)。每当我尝试安装一个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>

看起来今天 VS Code 和 Python 出了一些严重的问题:https://stackoverflow.com/questions/52873612/ - DeepSpace
你是否曾经找出了问题所在? - Giuseppe Romagnuolo
2个回答

1

尝试检查您的Python版本。当我尝试在VScode中运行我的Python3代码时,我遇到了类似的错误。尝试在VScode中更改Python版本。


我刚刚尝试了3.6版本,但是出现了相同的错误。正如我之前提到的,调试器在不到24小时前使用完全相同的Python版本时可以工作。 - Kyruski
尝试其他版本。 - Tech guy
切换版本并不能解决问题。 - Kyruski
尝试使用虚拟环境在Linux上运行您的代码。 - Tech guy
1
这跟我的问题有什么关系?我可以在命令行中正常运行代码。问题出在VSCode和Python上。我无法进行调试或安装linter(我想其他东西也是一样的)。这在我的笔记本电脑和台式电脑上同时发生。这是在一天前一切正常之后发生的。 - Kyruski
然后卸载VSCode,清除所有VScode首选项(备份以防需要),重新安装VScode,安装扩展,祝你好运。 - Tech guy

0
如果有人需要帮助,我曾经遇到这样一种情况:突然间我的 Python 代码在 VS Code 中似乎无法进行调试了。状态栏底部会有一个短暂的颜色变化,然后就没有反应了。原来是在包含“main()”的那一行之前不小心插入了一个空行。我把它删除了,问题迎刃而解!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接