title: Python import file from the same directory: ModuleNotFoundError: No module named
body: <p>I have the following files. And I want to be able to run <code>python web\file1.py</code> in <code>Mod1</code>.</p>
  <pre><code>Mod1
    web
      __init__.py
      file1.py
      file2.py
    __init__.py
  </code></pre>
  <p>and in <code>file1.py</code>:</p>
  <pre><code>import web.file2
  </code></pre>
  <p>However, when I run the following command in the directory <code>mod1</code>:</p>
  <pre><code>....\Mod1&gt; python .\web\file1.py
  Traceback (most recent call last):
    File &quot;.\web\file1.py&quot;, line 1, in &lt;module&gt;
      import web.file2
  ModuleNotFoundError: No module named 'web'
  </code></pre>
  <p>I tried to change the content of <code>file1.py</code> to</p>
  <pre><code>from . import file2
  </code></pre>
  <p>and the error become</p>
  <pre><code>ImportError: attempted relative import with no known parent package
  </code></pre>