Importing modules used in a package in __init__.py
<p>I have the following directory structure:</p>

<pre><code>funniest/
    setup.py
    funniest/ 
          __init__.py
          ModuleA.py
          ModuleB.py
</code></pre>



<pre><code># __init__.py
from numba import jit

from .ModuleA import ClassA
</code></pre>



<pre><code># ModuleA.py
import funniest.ModuleB

class ClassA():
    pass
</code></pre>



<pre><code># ModuleB.py
@jit
def f():
    pass
</code></pre>

<p>However, when importing the module, I get the error message:</p>

<pre><code>&gt;&gt;&gt; import funniest
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in &lt;module&gt;
File "/home/domi89/Dropbox/Python_Projects/funniest/funniest  /__init__.py", line 2, in &lt;module&gt;
from .ModuleA import ClassA
File "/home/domi89/Dropbox/Python_Projects/funniest/funniest /ModuleA.py", line 1, in &lt;module&gt;
import funniest.ModuleB
File "/home/domi89/Dropbox/Python_Projects/funniest/funniest/ModuleB.py", line 1, in &lt;module&gt;
@jit
NameError: name 'jit' is not defined
</code></pre>

<p>I cannot understand why this happends, because when <code>__init__.py</code> get executed first, the first thing it does is importing <code>from numba import jit</code>. So why is <code>jit</code> not defined when it comes to function <code>f</code> in <code>ModuleB</code>?    </p>

<p>The imports you put in <code>funniest/__init__.py</code> are only imported when you do <code>import funniest</code>, not automatically inside submodules. So <code>ModuleB</code> doesn't know about <code>jit</code>.</p>

<p>What you need to do here is to move <code>from numba import jit</code> from <code>__init__.py</code> to <code>ModuleB.py</code>.</p>

python