Reputation: 565
I am doing a mini project in python. My base folder is 'DB'. When imports are between files in this folder they work fine. I have a folder 'GUI' inside my 'DB' folder. When I do imports between files within this 'GUI' folder it gives error.
So I tried moving the files to the base folder and imports worked fine.
So how can I make my import work fine as well as have those files in 'GUI' folder.
projects/DB/GUI/frame.py:
class mygui:
...
....
projects/DB/GUI/wrapper.py:
from frame import mygui # ===>error
P.S.This is my first Py project.
Upvotes: 1
Views: 157
Reputation: 32542
do you have a (probably empty) __init__.py
file in your subdirectory?
(Python needs one to consider the directory as a module package that is importable.)
then try to do
from GUI.frame import mygui
you also need this step if GUI modules import other GUI modules (given your working directory is the base path).
see this article for more details on this.
Upvotes: 3