Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode python debug: "No module named xx" when using module attribute

My Python project folder structure is as follow:

.python_practice
|--lib
    |--lib.py
    |--__init__.py
|--practice1
    |--my_module.py
    |--__init__.py
|--__init__.py

My launch configuration is

{
    "name": "Python: Module",
    "type": "python",
    "request": "launch",
    "module": "practice1.my_module",
    "console": "integratedTerminal"
 },

In my_module.py

from lib.lib import util_func

When I try to debug using VScode I get an error: "No module named practice1.my_module"

But when I run it with the following command it works fine

python -m practice1.my_module

How could I debug my code so that the relative import work?

Any help will be appreciated, thank you.

like image 938
Dev Khadka Avatar asked Nov 15 '18 16:11

Dev Khadka


People also ask

How do I debug a Python module in VSCode?

You can also start the debugger by clicking on the down-arrow next to the run button on the editor, and selecting Debug Python File in Terminal. The debugger will stop at the first line of the file breakpoint. The current line is indicated with a yellow arrow in the left margin.

Can I debug Python in VSCode?

Start by clicking on the debug icon on the left-hand panel of your VSCode. Click on create a launch. json file, which will give you a drop-down of all your currently installed debuggers. By default, a Python debugger is not installed in VSCode.

What is disable debug mode in VS code?

To end a debugging session in Microsoft Visual Studio, from the Debug menu, choose Stop Debugging.


1 Answers

This is a known bug involving debugging sub-modules.

like image 62
Brett Cannon Avatar answered Oct 23 '22 08:10

Brett Cannon