I created workspace_folder
, cloned a github repo
(folder name) which has repo_module
folder, which in turn has train.py
and algo.py
:
workspace_folder
|
+-- repo
|
+-- train.py
|
+-- algo.py
The repo's readme asks to run:
python -m repo_module.train
which I am able to run from within repo
folder:
workspace_folder/repo$ python -m repo_module.train
But I want to debug the train.py
in vscode. I opened train.py
and started debugging with Python: Current File
configuration. But it started giving me following error:
Exception has occurred: ImportError
attempted relative import with no known parent package
for line from . import algo
in train.py
.
Answer here suggests that we need to do some changes to the code. I was thinking if I can make any changes to vscode debug launch.json
and make it work. I tried to set "cwd": "${workspaceFolder}/repo"
in launch.json
but it gave same error. So, for now I have replaced all from .
(space after dot .
) with empty string in all files (converting all from . import abc
to import abc
) and from .
(no space after .
) to from
in all files(converting all from .abc
to from abc
) and am able to debug it. But I was able to guess if I can do away with modifying code and configuring in vscode launch.json
. Is it possible.
(Also note that my changes seem to have worked as all py files are "directly" inside repo
folder and there is no subfolder inside repo
folder.)