1

I have a project with the following hierarchy and I am trying to use a class defined in the file Student.py in the file webcam_classifier.py. I do so like this:

from .Student import Student

However, I get the following error:

ModuleNotFoundError: No module named '__main__.Student'; '__main__' is not a package

I'm not sure what I'm doing wrong. Any help is appreciated!!!

enter image description here

mlz7
  • 2,067
  • 3
  • 27
  • 51
  • What's the purpose of `.` in `.Student`? – CristiFati Apr 21 '18 at 19:48
  • @CristiFati I was attempting to access the directory a level up from the current folder but it is probably a mistake. I'm not really sure as to what the right way of going about this is – mlz7 Apr 21 '18 at 19:52
  • Then you might want to add another one :) https://docs.python.org/3/tutorial/modules.html#intra-package-references – CristiFati Apr 21 '18 at 19:55
  • @CristiFati When I do so, I get the following error: `ValueError: attempted relative import beyond top-level package` – mlz7 Apr 21 '18 at 19:58
  • Then what about `from Models.Student`? – CristiFati Apr 21 '18 at 20:02
  • @CristiFati I get `ModuleNotFoundError: No module named 'Models'` – mlz7 Apr 21 '18 at 20:04
  • 1
    Possible duplicate of [How to do relative imports in Python?](https://stackoverflow.com/questions/72852/how-to-do-relative-imports-in-python) – Davis Herring Apr 21 '18 at 23:39

0 Answers0