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>

<p>Like said in comment, your tree looks strange. Put tests on the same level as address_book.</p>

<p>To run the tests, you should use auto test discovery tools like nose or pytest (in doubt, go for pytest). Those tools automatically find the packages they are testing so that you don't have to install them or care in any way about their presence in the PATH.</p>

<p>It might sound like a burden at first, having to learn a new tool, but it's pretty straightforward, and on the long run, pytest is really helpful.</p>

python