ImportError: No module named _thread

ImportError: No module named _thread

在vscode中编译python2会出错。 但是当我编译 python3 它成功了。

print('test')

returns: ImportError: 没有名为 _thread 的模块

PS C:\source>  c:; cd 'c:\source'; & 'C:\Python27\python.exe' 'c:\Users\keinblue\.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\lib\python\debugpy\launcher' '52037' '--' 'c:\source\test.py' 
Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "c:\Users\keinblue\.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\lib\python\debugpy\__main__.py", line 43, in <module>
    from debugpy.server import cli
  File "c:\Users\keinblue\.vscode\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 "c:\Users\keinblue\.vscode\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 "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "c:\Users\keinblue\.vscode\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 "c:\Users\keinblue\.vscode\extensions\ms-python.python-2022.4.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydev_bundle\_pydev_saved_modules.py", line 94, in <module>
    import _thread as thread;    verify_shadowed.check(thread, ['start_new_thread', 'start_new', 'allocate_lock'])
ImportError: No module named _thread

vscode python 扩展版本 2022.4.0

存在问题

只要降级到版本 2022.2.1924087327,它就会像现在对我一样工作

只需按照以下步骤操作:

  • 转到扩展程序。
  • 单击已安装扩展程序的齿轮图标
  • 点击安装另一个版本
  • select 您要安装的版本

我认为它是 VS 代码 Python 扩展。在 VS Code select Python 扩展和 select 卸载下拉菜单中安装以前的版本,2022.2.xxx 解决了这个问题。install previous version

今天我遇到了同样的问题。这些是我执行的修复步骤。

  1. 更新扩展到v2022.6.2
  2. 版本
  3. 重新加载VSCode
  4. 重新启动相关应用程序

它对我来说很顺利。