Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'services'

Tags:

python

ModuleNotFoundError: No module named 'services'

Totally new to Python, please pardon for this stupid question. I'm following a nice tutorial which has this structure: enter image description here

deskew_service.py has this line looks perfect as it tries to import from another file in the same folder where it has class GraphicsService():

enter image description here

After reading other SO posts, Python 3.x would use from .<folder/package> import <classname>, but from .services import GraphicsService still the same.

Running this script tests\test_deskew.py contains the following got ModuleNotFoundError: No module named 'services'

enter image description here

Python v 3.9.5

like image 377
Jeb50 Avatar asked Sep 05 '25 03:09

Jeb50


1 Answers

Thanks to @furas and @jakub. Here are the "how":

  • among classes in same folder/package, from .filename import classname, for example from above, from .graphics_service import GraphicsService.
  • in sibling folder, from ..foldername import classname, i.e. from ..services import DeskewService
like image 137
Jeb50 Avatar answered Sep 07 '25 20:09

Jeb50