I am doing the following:
mkdir folder_structure
mkdir folder_structure/utils
touch folder_structure/utils/tools.py
touch folder_structure/main.py
- Write in main.py:
from folder_structure.utils.tools import dummy
if __name__ == '__main__':
dummy()
- Write in tools.py:
def dummy():
print("Dummy")
-
touch folder_structure/__init__.py
-
touch folder_structure/utils/__init__.py
-
Run the vs code debugger
I’m getting:
Exception has occurred: ModuleNotFoundError
No module named 'folder_structure'
File "/Users/davidmasip/Documents/Others/python-scripts/folder_structure/main.py", line 1, in <module>
from folder_structure.utils.tools import dummy
I have the following in my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
}
}
]
}
How can I import a local module when using the debugger?
This works for me:
python -m folder_structure.main
2
Answers
Changing the launch.json to this:
and debugging the module works.
You need replace
With