My module has __init__.py and still Python can't import it
<p>I have a small python module </p>

<pre><code>+-- address_book
|   +-- models.py
|   +-- __init__.py 
    +-- test
    |   +-- test_models.py 
</code></pre>

<p>When I run <code>python address_book/test/test_models.py</code> I get this error </p>

<pre><code>Traceback (most recent call last):
  File "address_book/test/test_models.py", line 5, in &lt;module&gt;
    from address_book import models
ImportError: No module named 'address_book'
</code></pre>

<h1>test_models.py</h1>

<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest
from address_book import models
...
...
...
if __name__ == '__main__':
    unittest.main()
</code></pre>

<pre><code>There is problem with import of module from parent directory as __main__ lies in child folder
if you do the folder structure like below your same code for import will work

+----test
     +---test_models.py
     +---__init__.py
     +---address_book
         +---__init__.py
         +---models.py
</code></pre>

<p>or you can add your project path to PYTHONPATH variable and your same code will work</p>

python