1

Recently ,My Visual Studios Code can't run in "Start Debugging" ,but it can run in "Run Without Debugging" .

The error message show it can't find the _thread module . The _thread module is in Python3 , I think the debugging mode using the Python3 configuration ,but I can't find where I can setting the debugging configuration

How should I do any setting to make my debugging can work ?

Below is my error message:

(venv) linlowa@linlowa-MacBook-Pro lab01 %  cd /Users/linlowa/Documents/company/python_lab/lab01 ; /usr/bin/env /Users/li
nzeyu/Documents/company/python_lab/lab01/venv/bin/python /Users/linlowa/.vscode/extensions/ms-python.python-2022.4.0/pythonFi
les/lib/python/debugpy/launcher 55883 -- /Users/linlowa/Documents/company/python_lab/lab01/lab01.py linlowa 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/linlowa/.vscode/extensions/ms-python.python-2022.4.0/pythonFiles/lib/python/debugpy/__main__.py", line 43, in <module>
    from debugpy.server import cli
  File "/Users/linlowa/.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 "/Users/linlowa/.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 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/linlowa/.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 "/Users/linlowa/.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
6
  • You need to select a python version on vscode. It looks like is taking the default Python version of your local machine. So you need to install a virutalenv that contains a different python version and that doesn't cause any conflicts with your Pythons local installation Commented Apr 7, 2022 at 3:17
  • Yes ,I had installed the virtualenv package ,but vscode still can not run in debugging. Commented Apr 7, 2022 at 3:43
  • 2
    please share your launch.json and settings.json file Commented Apr 7, 2022 at 7:22
  • launch.json{ "version": "0.2.0", "configurations": [ { "name": "Python: 目前檔案", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal" ,"args": ["linlowa"] } ] } setting.json { "python.formatting.provider": "autopep8" } Commented Apr 8, 2022 at 2:29
  • @linlowa Have you had any problems with debugging before? After reading the contents of your two files, I feel that it is not the problem of the configuration file Commented Apr 8, 2022 at 6:41

1 Answer 1

3

Try the following:


Click cmd + shift + p and search for Python: select interpreter. Then select the correct one

Vscode command bar

https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment


Set global default interpreter to python3 or python3.x in settings:

Default python interpreter setting


Making a new folder/workspace, and debug a test script. Make sure this new folder is not a virtual environment, to test if venv is the issue.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried it ,but still get the error
Have you tried rebuilding your launch/debug config?
Yes ,I had remove my launch.json file ,but it still appear this error .
I'll add a few more things to try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.