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.
-
And which error are you getting?Lasse V. Karlsen– Lasse V. Karlsen2012年03月10日 11:01:15 +00:00Commented Mar 10, 2012 at 11:01
-
are you using Django..??..and is your IDE : PyDev / Eclipse..??Ramandeep Singh– Ramandeep Singh2012年03月10日 11:07:26 +00:00Commented Mar 10, 2012 at 11:07
-
No django.Just a plain python project.I am using APTANA STUDIO(which uses the same 'PyDev' )Sudhagar Sachin– Sudhagar Sachin2012年03月10日 11:10:29 +00:00Commented Mar 10, 2012 at 11:10
-
Check your pythonpath. You need to include the parent directory of your Project in it..!!..I suppose from DB.GUI.frame import mygui would work..!!Ramandeep Singh– Ramandeep Singh2012年03月10日 11:11:42 +00:00Commented Mar 10, 2012 at 11:11
1 Answer 1
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.