title: VSCode ModuleNotFoundError: No module named X
body: <p>I am trying to build a new package, however, when I try to run any of the files from inside VSCode or from terminal, I am coming across this error:</p>
  <pre><code>ModuleNotFoundError: No module name 'x'
  </code></pre>
  <p>My current folder structure is as follows:</p>
  <pre><code>package
  |---module
  |------__init__.py
  |------calculations.py
  |------miscfuncs.py
  |---tests
  |------__init__.py
  |------test_calcs.py
  |---setup.py
  |---requirements.txt
  </code></pre>
  <p>However, when I run my tests (PyTest) through VSCode and using <code>import module.calculations as calc</code> or <code>from module.calculations import Class</code> in test_calcs.py, the tests work as expected - which is confusing me.</p>
  <p>I know this is a commonly asked question, but I cannot fathom out a solution that will work here.</p>
  <p>I have tried checking the working directory is in system path using the code below. The first item on the returned list of directories is the one I am working in.</p>
  <pre><code>import sys
  print(sys.path)
  </code></pre>
  <p>I have also used the following in the files to no avail:</p>
  <pre><code>import module.calculations 
  import .module.calculations
  from . import miscfuncs
  </code></pre>
  <p>When trying <code>import .module.calculations</code>, I get the following:</p>
  <pre><code>ModuleNotFoundError: No module named '__main__.module'; '__main__' is not a package
  </code></pre>
  <p>When trying <code>from . import miscfuncs</code> in calculations.py, I get the following error:</p>
  <pre><code>ImportError: cannot import name 'miscfuncs'
  </code></pre>
  <p>When working on a file within the module folder, I can use a relative import: <code>import calculations</code> and it works fine. This is fine for files within module, but not when I am working in test_calcs.py.</p>
  <p>In my setup.py, I have a line for:</p>
  <pre><code>packages=['module']
  </code></pre>
  <p>Happy to post more info if required or a link to my repo for the full code.</p>
  <p><strong>EDIT</strong></p>
  <p>Following remram's solution:</p>
  <p>I have updated <code>launch.json</code> to include the <code>CWD</code> and <code>PYTHONPATH</code> variables.</p>
  <p>The module name is still not recognised, however, IntelliSense within VSCode is picking up the functions within the imported file just fine.</p>
  <pre><code>&quot;version&quot;: &quot;0.2.0&quot;,
  &quot;configurations&quot;: [
      {
          &quot;name&quot;: &quot;Python: Current File&quot;,
          &quot;type&quot;: &quot;python&quot;,
          &quot;request&quot;: &quot;launch&quot;,
          &quot;program&quot;: &quot;${file}&quot;,
          &quot;console&quot;: &quot;integratedTerminal&quot;,
          &quot;cwd&quot;: &quot;${workspaceFolder}&quot;,
          &quot;env&quot;: {&quot;PYTHONPATH&quot;: &quot;${cwd}&quot;
          }
      }
      ]
  </code></pre>