Python import issue

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

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

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

  • the app/ 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')
import module