Python import module error
<p>I have a problem in import of modules in my project. I was creating tests and I cant import my main to test one end point of my application, from the test file <code>teste_ex.py</code>. This is my project structure:</p>

<pre><code>backend_api/
    api/
        __init__.py
        main.py
    testes/
        __init__.py
        test_ex.py
</code></pre>

<p>In my test_ex.py Im trying to import <code>main</code> in this way:</p>

<pre><code>import api.main
from webtest import TestApp

def test_functional_concursos_api():
    app = TestApp(main.app)
    assert app.get('/hello').status == '200 OK'
</code></pre>

<p>I omly get <code>ImportError: No module named 'api'</code></p>

<ul>
<li>What can be done to import my main to my test file?</li>
</ul>

<p>Here's my best guess as to what might help:</p>

<p>You should make sure that the path to the directory in which your <code>main.py</code> file resides can be found in <code>sys.path</code>.  You can check this yourself by running this snippet in <code>test_ex.py</code>:</p>

<pre><code>import sys

for line in sys.path:
    print line
</code></pre>

<p>If the directory in which <code>main.py</code> is found is <em>not</em> included in your <code>path</code>, you can append that path to <code>sys.path</code>, like this (include this snippet in <code>test_ex.py</code>):</p>

<pre><code>import sys
sys.path.append("/path/to/your/module/backendapi/api/")
</code></pre>

python import