profile
viewpoint

Ask questionsImportError: can't find '__main__' module

python 2.7. Version: 1.38.1 Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0 Date: 2019-09-11T13:30:08.229Z Electron: 4.2.10 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0 OS: Linux x64 5.0.0-29-generic

Traceback (most recent call last):
  File "/home/user/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "/home/user/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/__main__.py", line 432, in main
    run()
  File "/home/user/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/usr/lib/python2.7/runpy.py", line 268, in run_path
    mod_name, loader, code, fname = _get_main_module_details()
  File "/usr/lib/python2.7/runpy.py", line 137, in _get_main_module_details
    (main_name, sys.path[0]))
ImportError: can't find '__main__' module in '/home/user/myproject/'
microsoft/ptvsd

Answer questions karthiknadig

@m0tz There were two issues:

  1. "program": should point to a python file. The Python extension picks up the executable based on the version of python selected via the interpreter selection UI. In your setting it was pointing to a directory (your workspace folder).
  2. "args": are a list of arguments that you pass to your python script or module. In your case the args were [ "python", "manage.py", "runserver_plus"]. This is equivalent to: /usr/bin/python python manage.py runserver_plus. See python is there twice, this causes the debugger to try to load python.__main__.

How did you find the debug config that you used?

useful!
source:https://uonfu.com/
answerer
Karthik Nadig karthiknadig @Microsoft Redmond Developer at Microsoft, working on VS Code Python and Python Debugger.
Github User Rank List