1

I have this structure of a python project:

RF

\__init__.py

----tools

--------\__init__.py

--------drawtools.py

----examples

--------\__init__.py

--------something.py

All __init__.py are left blank. Now, in "something.py" I type:

from RF.tools.drawtools import *

And I get:

ImportError: No module named RF.tools.drawtools

What's the correct program structure? Do I have to put something in the init files? I notice that if "something.py" is in the top directory it works. The strange thing is that PyCharm, the IDE I'm using, seems to recognize the import and give me code completion.

I heard something about setting PYTHONPATH but as this project must be shared in a team I'd prefer to keep things as simple as possible (you copy the project from one to one and run it without any annoying importError).

rypel
  • 4,686
  • 2
  • 25
  • 36
blueSurfer
  • 5,651
  • 13
  • 42
  • 63
  • *something.py* is supposed to be a program, right? It does not work like that. Please have a look at [*__main__.py*](http://stackoverflow.com/questions/4042905/what-is-main-py). :) – Gandaro Oct 16 '12 at 16:59
  • see http://stackoverflow.com/questions/72852/how-to-do-relative-imports-in-python – ErwinP Oct 16 '12 at 17:19

1 Answers1

0

I think that it would work with a relative import, such as

from .. import drawtools
Olivier Verdier
  • 46,998
  • 29
  • 98
  • 90