title: Python Import Submodule Prefix
body: <p>I am getting a little frustrated with python imports at the moment. I think I am honestly just remembering something wrong and performing the import incorrectly.</p>
  
  <p>I have the following directory structure for my application:</p>
  
  <pre><code>open_app
  |-  __init__.py
  |-  open_app.py
  |-  core/
  |  |- __init__.py
  |  |- data/
  |  |  |- __init__.py
  |  |  |- data.py
  |  |- settings/
  |  |- interface/
  |-  extensions/
  </code></pre>
  
  <p>In <strong>init</strong>.py I have the following:</p>
  
  <pre><code>import open_app.Open_App as Open_App
  if __name__ == "__main__":
      main = Open_App()
      input("Press a key to continue")
  </code></pre>
  
  <p>In open_app.py I have the following:</p>
  
  <pre><code>from core import data as Data
  class Open_App():
      pass
  </code></pre>
  
  <p>In core/<strong>init</strong>.py, I have nothing.</p>
  
  <p>in core/data/<strong>init</strong>.py I have the following:</p>
  
  <pre><code>from data import Data as Data
  </code></pre>
  
  <p>In core/data/data.py I have the following:</p>
  
  <pre><code>class Data():
      pass
  </code></pre>
  
  <p>The problem is that when I run the module using IDLE, I get the following error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "F:\Personal\Code\Python\open_app\__init__.py", line 1, in &lt;module&gt;
      import open_app.Open_App as Open_App
    File "F:\Personal\Code\Python\open_app\open_app.py", line 1, in &lt;module&gt;
      from core import data as Data
    File "F:\Personal\Code\Python\open_app\core\data\__init__.py", line 1, in &lt;module&gt;
      from data import Data as Data
  ImportError: No module named 'data'
  </code></pre>
  
  <p>I am just trying to get the import to work. So I decided to change the</p>
  
  <p>core/data/<strong>init</strong>.py file to:</p>
  
  <pre><code>from core.data.data import Data as Data
  </code></pre>
  
  <p>Which works. But to me this doesn't seem like a very good solution. It doesn't make sense to me to have to prefix all submodules with every module directory above it. It would make it very difficult as the project gets larger to perform a unit test.</p>
  
  <p>Why do I have to prefix the names like that? Since the <strong>init</strong>.py exists in the </p>
  
  <p>core/data </p>
  
  <p>directory, I should think that:</p>
  
  <p>core/data/data.py</p>
  
  <p>Would be visible and importable. In practice it is not.</p>
  
  <p>What am I doing wrong? I feel very humbled to have to ask thins, and I am sorry that this is basic, but I appreciate any help in advance. I have been reading the PEP documentation on importing and something just isn't clicking.</p>
  
  <p>Thanks in advance!</p>