0

I am new to Python's module and package system. I currently have the following directory structure

ProjectDirectory:

Main.py
 
EntitiesDirectory/
       
        __init__.py
        Trip.py
        Plan.py

The init.py file is empty. The Plan.py contains a class definition for the class Plan. The class Trip looks like this

 from  Plan import Plan
 Class Trip():
     def__init__(self,plan:"Plan"):
           do something with the plan object

When I run the Trip.py file inside from the Entities directory, there is no problem. However, when I try to import it n the Main.py file, I get the following error

from Entities.Trip import Trip
No module named Plan

I have tried work the following changes inside Trip.py file

from .Plan import Plan
from Entities.Plan import Plan
from . import Plan

However nothing worked (relative directory error with no parent module). I am using Python 3.11 inside Anaconda.

kangkan Dc
  • 183
  • 1
  • 9
  • Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – Brian61354270 Jul 27 '23 at 14:22
  • Please note that imports _do not navigate directories_. Imports are only resolved by searching the Python path. `from .X` doesn't mean "in the same directory", it means "use the current package name as the base for the fully qualified dotted name of the package to import" – Brian61354270 Jul 27 '23 at 14:24

0 Answers0