I have tried different solutions to enable me to debug a python file in my project.
Here is my file structure:
project-main
-ns
-examples
and several Python files in examples and ns. Basically, all example files are using ns or other imported modules. I also have a conda environment that I have already activated in vs code terminal. And here is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Module",
"type": "python",
"request": "launch",
"module": "project-main.examples",
}
]
}
I select Start debugging from the Run menu but I keep getting this error:
E+00000.063: Error determining module path for sys.argv
Traceback (most recent call last):
File "c:Usersmyuser.vscodeextensionsms-python.python-2023.8.0pythonFileslibpythondebugpy/..debugpyservercli.py", line 296, in run_module
spec = find_spec(options.target)
File "C:UsersmyuserAppDataLocalProgramsPythonPython310libimportlibutil.py", line 94, in find_spec
parent = __import__(parent_name, fromlist=['__path__'])
ModuleNotFoundError: No module named 'project-main'
.
.
.
File "c:Usersmyuser.vscodeextensionsms-python.python-2023.8.0pythonFileslibpythondebugpy/..debugpycommonlog.py", line 215, in swallow_exception
_exception(format_string, *args, **kwargs)
C:UsersmyuserAppDataLocalProgramsPythonPython310python.exe: Error while finding module specification for 'project-main.examples' (ModuleNotFoundError: No module named 'project-main')
2
Answers
Here is the correct config:
so basically for the module field, I have to enter the name of the subfolder that includes the main running file (run_this) and then the name of the running file.
Based on the information you provided, I provide a possible answer. If your module
project-main
is located under the workspace, you can try the following way.If you didn’t set
cwd
, default would be the root directory of the file. During the debugging process, the module cannot be found. You can setcwd
in thelaunch.json
file by add the following codes: