Import Error on trying to import a submodule that imports a submodule
<p>I feel like I'm missing something simple and basic. Here's a toy setup</p>

<pre><code>PythonProject/
main.py
x/
    a.py
    y/
        b.py
</code></pre>

<p>b.py has a function foo with no dependencies</p>

<pre><code>def foo():
    print("Hello World")
</code></pre>

<p>a.py needs foo from b.py to work and imports it directly</p>

<pre><code>import y.b
def bar():
    #Do some stuff
    y.b.foo()
</code></pre>

<p>main.py needs bar from a.py</p>

<pre><code>import x.a
x.a.bar()
</code></pre>

<p>Now, running a.py works just fine, it successfully imports b and finds foo.
Trying to run main.py however breaks with an import error: specifically "import b" fails during "import a"</p>

<p>I get the impression that what needs to happen is that <code>b</code> needs to be exposed by an <code>__init__.py</code> in <code>a/</code> but I'm unsure what the pythonic way of doing this would be.</p>

<p>What is the preferred solution to importing a module (a) which imports another module (b) preferably without bringing PythonProject awareness to a?</p>