It is __init__.py
not init.py
. Make sure each of the directory in hierarchy contains it in order to be able to import.
EDIT: I managed to reproduce it.
Here's the directory structure:
cesar@cesar-laptop:/tmp/asdasd$ tree
.
`-- myapp
|-- __init__.py
|-- models
| |-- __init__.py
| `-- models.py
|-- scripts
| |-- data.py
| `-- __init__.py
`-- tests
|-- __init__.py
`-- tests.py
I put the following code at the very beginning of the data.py
to narrow down the problem:
import sys
import pprint
pprint.pprint(sys.path)
from myapp.models.models import *
Running the data.py
the way OP indicated yeilds ImportError:
cesar@cesar-laptop:/tmp/asdasd$ python myapp/scripts/data.py
['/tmp/asdasd/myapp/scripts',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
-- Skipped --
'/usr/local/lib/python2.6/dist-packages']
Traceback (most recent call last):
File "myapp/scripts/data.py", line 6, in
from myapp.models.models import *
ImportError: No module named myapp.models.models
But this way works like a charm:
cesar@cesar-laptop:/tmp/asdasd$ python -m myapp.scripts.data
['',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
-- Skipped --
'/usr/local/lib/python2.6/dist-packages']
Note the difference in the first entry of sys.path
.