Structuring a multi-component Python application to share modules
<p>I've created a program with two stand-alone components (app1 and app2 below), that are both stand-alone but share a couple of basic modules (stored in app1).
I'm now trying to merge these two apps together into one application. My application has a structure like this:</p>

<pre><code>/root
    |-docs
    |-config
    |-app1
    |   |-src
    |   |   |-main.py
    |
    |-tests
    |    |-a_tests.py
    |-app2
    |    |-API
    |    |-web-server.py
    |    |    |-REST.py
</code></pre>

<p>I have a few requirements:</p>

<ul>
<li>/app2/API/REST.py and its kin needs to be able to read modules from /app1/src/</li>
<li>/tests/ needs to be able to read modules from both app1 and app2.
The tests are currently all written for /app1/, but I've since moved app1 into a directory deeper and thus they've all stopped working.</li>
</ul>

<p>I know I may need to use some <code>__init__.py</code> files (/root/ and all the directories with python files in have an empty one presently) and I've tried <code>__path__</code> too, but I keep getting <code>ImportError: No module named &lt;main.py&gt;</code> errors.
I note this question - <a href="https://stackoverflow.com/questions/16637428/relative-import-in-python-3-not-working">Relative import in Python 3 not working</a> - and when I try to use a relative import from app2 to app1, I get that error message. But that question only says I need to use absolute imports, not how to do them.</p>

<p>How do I accomplish this?</p>