由于阴影,VSCode 调试器无法导入队列

onu*_*ore 12 python python-2.7 visual-studio-code

当我尝试使用 VScode 在调试模式下运行任何 python 代码时,我收到一条错误消息:

42737 -- /home/<username>/Desktop/development/bopi/experiment_handler.py .vscode-server/extensions/ms-python.python-2022.4.0/pythonFiles/lib/python/debugpy/launcher 4
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/<username>/.vscode-server/extensions/ms-python.python-2022.4.0/pythonFiles/lib/python/debugpy/__main__.py", line 43, in <module>
    from debugpy.server import cli
  File "/home/<username>/.vscode-server/extensions/ms-python.python-2022.4.0/pythonFiles/lib/python/debugpy/../debugpy/server/__init__.py", line 9, in <module>
    import debugpy._vendored.force_pydevd  # noqa
  File "/home/<username>/.vscode-server/extensions/ms-python.python-2022.4.0/pythonFiles/lib/python/debugpy/../debugpy/_vendored/force_pydevd.py", line 37, in <module>
    pydevd_constants = import_module('_pydevd_bundle.pydevd_constants')
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/<username>/.vscode-server/extensions/ms-python.python-2022.4.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_constants.py", line 362, in <module>
    from _pydev_bundle._pydev_saved_modules import thread, threading
  File "/home/<username>/.vscode-server/extensions/ms-python.python-2022.4.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py", line 97, in <module>
    import queue as _queue;    verify_shadowed.check(_queue, ['Queue', 'LifoQueue', 'Empty', 'Full', 'deque'])
  File "/home/<username>/.vscode-server/extensions/ms-python.python-2022.4.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py", line 75, in check
    raise DebuggerInitializationError(msg)
_pydev_bundle._pydev_saved_modules.DebuggerInitializationError: It was not possible to initialize the debugger due to a module name conflict.

i.e.: the module "queue" could not be imported because it is shadowed by:
/home/<username>/.local/lib/python2.7/site-packages/queue/__init__.pyc
Please rename this file/folder so that the original module from the standard library can be imported.
Run Code Online (Sandbox Code Playgroud)

删除init .pyc 和init .py 会导致出现有关缺少队列导入的错误消息。

小智 25

将 Visual Studio Code 中的 Python 扩展降级v2022.2.1924087327为我所用。

将下面@Onur Berk 的评论作为答案的一部分进行提升:

降级Python扩展非常容易,只需单击“扩展”并找到Python扩展并选择它即可。不要单击“卸载”,而是单击旁边的箭头,这将为您提供安装另一个版本的选项

  • 降级Python扩展非常容易,只需单击“扩展”并找到Python扩展并选择它即可。您无需单击“卸载”,而是单击旁边的箭头,这样您就可以选择安装另一个版本。 (2认同)
  • 我要补充的是,为了使其工作,我还必须重新启动 VS Code。 (2认同)