Python import issue

II got this error:
ModuleNotFoundError: No module named ‘package’
here are the contents of each file:

  • package/module.py:
    class Animal():
    def init(self): print(“an animal”)
  • package/init.py:
    from .module import Animal
  • app/main.py:
    from package import Animal
    print(Animal())

what is the issue here??? the project structure is:
Untitled

  • the app/main.py is the entry point.
  • i run the app through vsCode which in of itself is ran via the terminal after navigating to the root dir the running [code.].

The package isn’t in the class path. It doesn’t know where to look for package. It only knows of the current folder and everything below it. Here’s how I would fix it and would involve manually adding it to the classpath. We find the folder with the sys module and we append it to our path. Then we import.

import sys
import os

script_dir = os.path.dirname(__file__)
mymodule_dir = os.path.join(script_dir, '..', 'package')
sys.path.append(mymodule_dir)
import module
print(module.Animal())