title: Yet another ImportError: attempted relative import with no known parent package
body: <p>I have the following directory structure:</p>
  
  <pre><code>py_test
  ├── __init__.py
  ├── dir1
  │   ├── __init__.py
  │   └── script1.py
  └── dir2
      ├── __init__.py
      └── script2.py
  </code></pre>
  
  <p>In <code>script2</code> I want to "<code>import ..\script1</code>".</p>
  
  <p>What I tried in <code>script2</code>:</p>
  
  <ol>
  <li><p>Does not work</p>
  
  <pre><code>from ..dir1 import script1
  ImportError: attempted relative import with no known parent package`
  </code></pre></li>
  <li><p>Works</p>
  
  <pre><code>import sys, os
  path2add = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'dir1')))
  if (not (path2add in sys.path)) :
      sys.path.append(path2add)
  </code></pre></li>
  </ol>
  
  <p><strong>If I want to go with option 1, what is the simplest (i.e., with the least files) file/dir structure that makes it work?</strong>
  I am aware of <a href="https://napuzba.com/a/import-error-relative-no-parent" rel="noreferrer">this</a>, but I wonder if creating that directory structure can be avoided, and still use type-1 <code>import</code>.</p>
  
  <p>I am currently using <a href="https://stackoverflow.com/a/1054293/2707864">this workaround</a>, which uses type-2 <code>import</code>.</p>
  
  <p>Related:</p>
  
  <p><a href="https://stackoverflow.com/questions/1054271/how-to-import-a-python-class-that-is-in-a-directory-above">How to import a Python class that is in a directory above?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/32767362/import-a-module-from-a-directory-package-one-level-up/32767774">Import a module from a directory (package) one level up</a></p>
  
  <p><a href="https://stackoverflow.com/questions/45088071/getting-importerror-attempted-relative-import-with-no-known-parent-package-wh">Getting &quot;ImportError: attempted relative import with no known parent package&quot; when running from Python Interpreter</a></p>
  
  <p><a href="https://stackoverflow.com/questions/50884100/using-importlib-to-dynamically-import-modules-containing-relative-imports">Using importlib to dynamically import module(s) containing relative imports</a></p>
  
  <p><a href="https://stackoverflow.com/questions/59176229/how-to-import-variables-in-a-different-python-file">How to import variables in a different python file</a></p>