title: How to run python in Visual Studio Code as a main module
body: <p>How to run python in Visual Studio Code as a <strong>main module</strong>?</p>
  
  <p>From the command line I would use the <code>-m</code> switch, like</p>
  
  <pre><code>python -m program.py
  </code></pre>
  
  <p>I need this to make relative imports work.</p>
  
  <p>Is there something I could add to the <code>launch.json</code> file?</p>
  
  <p>If this isn't possible, I maybe need to do something with <code>runpy</code> <a href="https://docs.python.org/3/library/runpy.html" rel="noreferrer">see python docs</a>, but it would be nice if vscode can do this.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>For the moment I use, as a workaround, an extra <code>run.py</code> file which I place outside the package I want to run. Then configure vscode to run that file:</p>
  
  <pre><code>"program": "${workspaceRoot}/../run.py"
  </code></pre>
  
  <p>From <code>run.py</code> I import the package and call its entry-point function.</p>