VSCode Python:枚举已安装的包时出错

Joy*_*ker 10 python pip visual-studio-code

我长期成功的 VSCode Python 设置莫名其妙地崩溃了。

请问下面的错误是什么意思?首先推荐的Python 3.12找不到_tkinter。我尝试安装较旧的版本并得到这个。我也无法使用 pip,它说“外部管理环境”。我迷路了。

%  cd /Users/ken/Teaching/Python2024 ; /usr/bin/env /opt/local/bin/python3.9 /Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher 64660 -- /Users/ken/Teaching/Python2024/turtle1.py 
E+00000.193: Error while enumerating installed packages.
             
 Traceback (most recent call last):
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/common/log.py", line 361, in get_environment_description
     report("    {0}=={1}\n", pkg.name, pkg.version)
 AttributeError: 'PathDistribution' object has no attribute 'name'

             
 Stack where logged:
   File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
     return _run_code(code, main_globals, None,
   File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
     exec(code, run_globals)
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/__main__.py", line 91, in <module>
     main()
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/__main__.py", line 21, in main
     log.describe_environment("debugpy.launcher startup environment:")
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/common/log.py", line 369, in describe_environment
     info("{0}", get_environment_description(header))
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/common/log.py", line 363, in get_environment_description
     swallow_exception("Error while enumerating installed packages.")
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/common/log.py", line 215, in swallow_exception
     _exception(format_string, *args, **kwargs)

E+00000.030: Error while enumerating installed packages.
             
 Traceback (most recent call last):
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 361, in get_environment_description
     report("    {0}=={1}\n", pkg.name, pkg.version)
 AttributeError: 'PathDistribution' object has no attribute 'name'
             
 Stack where logged:
   File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
     return _run_code(code, main_globals, None,
   File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
     exec(code, run_globals)
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
     cli.main()
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 415, in main
     api.ensure_logging()
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/api.py", line 61, in ensure_logging
     log.describe_environment("Initial environment:")
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 369, in describe_environment
     info("{0}", get_environment_description(header))
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 363, in get_environment_description
     swallow_exception("Error while enumerating installed packages.")
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 215, in swallow_exception
     _exception(format_string, *args, **kwargs)

             

E+00000.225: Error while enumerating installed packages.
             
 Traceback (most recent call last):
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 361, in get_environment_description
     report("    {0}=={1}\n", pkg.name, pkg.version)
 AttributeError: 'PathDistribution' object has no attribute 'name'
             
 Stack where logged:
   File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
     return _run_code(code, main_globals, None,
   File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
     exec(code, run_globals)
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
     cli.main()
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
     run()
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 281, in run_file
     log.describe_environment("Pre-launch environment:")
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 369, in describe_environment
     info("{0}", get_environment_description(header))
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 363, in get_environment_description
     swallow_exception("Error while enumerating installed packages.")
   File "/Users/ken/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/common/log.py", line 215, in swallow_exception
     _exception(format_string, *args, **kwargs)

Run Code Online (Sandbox Code Playgroud)

Nit*_*wit 12

安装后修复importlib-metadatadebugpy在我的venv


小智 6

这为我解决了这个问题(来自https://github.com/microsoft/debugpy/issues/1379):

在 site-packages 下找到 debugpy/common/log.py (按照您在输出中看到的路径)。找到该文件中的行:

吞咽异常(“枚举已安装的软件包时出错。”)}

将其替换为:swallow_exception(“枚举已安装的软件包时出错。”,level =“info”)

令人难以置信的是,这还没有发布。


sta*_*all 4

至少对于您显示的跟踪中的消息来说,它看起来与枚举已安装的软件包时的错误非常相似(至少通过跟踪)。#1379,尽管它是关于 Visual Studio 的调试。如果是同样的问题,根据维护者的说法,您可以忽略该消息,并且 debugpy 仍然可以正常工作。在更高版本的 debugpy 中,应将该日志消息分配给“info”日志级别。