title: How to resolve this import error in Python 3.6?
body: <p>I have a <a href="https://github.com/korommatyi/import-error-repro" rel="nofollow noreferrer">very simple namespace package</a> (contents included below, as well as the directory layout). If I try to import <code>namespace_repro.module</code>, I got the following error: <code>AttributeError: module 'namespace_repro' has no attribute 'module'</code>. As far as I understand my package has a valid layout and the import should work. Interestingly, the error is present only in Python 3.6.8 and the import succeeds in Python 3.7.</p>
  
  <h2>How to reproduce the problem?</h2>
  
  <p>I have a directory named <code>import-error-repro</code> with in it a <code>setup.py</code> (see below), then a nested directory path <code>src/namespace_repro/module</code>, containing three files, <code>__init__.py</code>, <code>x.py</code> and <code>y.py</code>. Their contents:</p>
  
  <p><code>setup.py</code></p>
  
  <pre><code>from setuptools import find_namespace_packages, setup
  
  setup(
      name='namespace-repro',
      version='0.1.0',
      python_requires='&gt;=3.6',
      packages=find_namespace_packages('src'),
      package_dir={'': 'src'},
      zip_safe=False,
  )
  </code></pre>
  
  <p><code>src/namespace_repro/module/__init__.py</code>:</p>
  
  <pre><code>from namespace_repro.module.x import x
  </code></pre>
  
  <p><code>src/namespace_repro/module/x.py</code>:</p>
  
  <pre><code>import namespace_repro.module.y as y
  
  x = y.y
  </code></pre>
  
  <p>and finally <code>src/namespace_repro/module/y.py</code>:</p>
  
  <pre><code>y = True
  </code></pre>
  
  <p>I created a brand new Python 3.6 conda environment by <code>conda create -n namespace6 python=3.6 ipython</code>, then I activated it and installed the package as <code>pip install -e ./import-error-repro</code> (note that <code>-e</code> doesn't matter, the problem is reproducible without it). After that, I tried  <code>import namespace_repro.module</code> in <code>ipython</code> (though the same happens in the official python interpreter). The result is</p>
  
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-1-bcae5a697dad&gt; in &lt;module&gt;
  ----&gt; 1 import namespace_repro.module
  
  ~/namespace-repro/src/namespace_repro/module/__init__.py in &lt;module&gt;
  ----&gt; 1 from namespace_repro.module.x import x
  
  ~/namespace-repro/src/namespace_repro/module/x.py in &lt;module&gt;
  ----&gt; 1 import namespace_repro.module.y as y
        2 
        3 x = y.y
  
  AttributeError: module 'namespace_repro' has no attribute 'module'
  ---------------------------------------------------------------------------
  </code></pre>
  
  <p>The strange thing is that the import system finds <code>namespace_repro.module</code> twice but fails at the third time!</p>
  
  <p>Some other interesting behaviour:</p>
  
  <pre><code>In [1]: import namespace_repro.module.y as y  # This doesn't work.
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-4-4035347ea59b&gt; in &lt;module&gt;
  ----&gt; 1 import namespace_repro.module.y as y
  
  AttributeError: module 'namespace_repro' has no attribute 'module'
  
  In [2]: import namespace_repro.module.y  # But this one does! Why?
  
  In [3]: dir(namespace_repro.module.y) # The error returns when we actually want to use the module.
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-3-d89bcfd9e509&gt; in &lt;module&gt;
  ----&gt; 1 dir(namespace_repro.module.y)
  
  AttributeError: module 'namespace_repro' has no attribute 'module'
  
  In [4]: from namespace_repro.module.y import y  # This works fine!
  
  In [5]: y
  Out[5]: True
  </code></pre>
  
  <h2>Directory layout</h2>
  
  <pre><code>. import-error-repro
  +-- setup.py
  +-- src
  |   +-- namespace_repro
  |   |   +-- module
  |   |   |   +-- __init__.py
  |   |   |   +-- x.py
  |   |   |   +-- y.py
  </code></pre>