1

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.

4
  • And which error are you getting? Commented Mar 10, 2012 at 11:01
  • are you using Django..??..and is your IDE : PyDev / Eclipse..?? Commented Mar 10, 2012 at 11:07
  • No django.Just a plain python project.I am using APTANA STUDIO(which uses the same 'PyDev' ) Commented 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..!! Commented Mar 10, 2012 at 11:11

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks dude.That article was helpful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.