title: Import local function from a module housed in another directory with relative imports in Jupyter Notebook using Python 3
body: <p>I have a directory structure similar to the following</p>
  
  <pre><code>meta_project
      project1
          __init__.py
          lib
              module.py
              __init__.py
      notebook_folder
          notebook.jpynb
  </code></pre>
  
  <p>When working in <code>notebook.jpynb</code> if I try to use a relative import to access a function <code>function()</code> in <code>module.py</code> with:</p>
  
  <pre><code>from ..project1.lib.module import function
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>SystemError                               Traceback (most recent call last)
  &lt;ipython-input-7-6393744d93ab&gt; in &lt;module&gt;()
  ----&gt; 1 from ..project1.lib.module import function
  
  SystemError: Parent module '' not loaded, cannot perform relative import
  </code></pre>
  
  <p>Is there any way to get this to work using relative imports? </p>
  
  <p>Note, the notebook server is instantiated at the level of the <code>meta_project</code> directory, so it should have access to the information in those files. </p>
  
  <p>Note, also, that at least as originally intended <code>project1</code> wasn't thought of as a module and therefore does not have an <code>__init__.py</code> file, it was just meant as a file-system directory. If the solution to the problem requires treating it as a module and including an <code>__init__.py</code> file (even a blank one) that is fine, but doing so is not enough to solve the problem.</p>
  
  <p>I share this directory between machines and relative imports allow me to use the same code everywhere, &amp; I often use notebooks for quick prototyping, so suggestions that involve hacking together absolute paths are unlikely to be helpful.</p>
  
  <hr>
  
  <p>Edit: This is unlike <a href="https://stackoverflow.com/questions/16981921/relative-imports-in-python-3">Relative imports in Python 3</a>, which talks about relative imports in Python 3 in general and – in particular – running a script from within a package directory. This has to do with working within a jupyter notebook trying to call a function in a local module in another directory which has both different general and particular aspects. </p>