title: Debug FastAPI application in VSCode
body: <p>i'm trying to debug an application (a web api) that use FastAPI (uvicorn)
  I'm also using poetry and set the projev virtual environment in vscode.</p>
  
  <p>i read <a href="https://fastapi.tiangolo.com/tutorial/debugging/" rel="noreferrer">this</a> tutorial to setup uvicorn and <a href="https://code.visualstudio.com/docs/python/debugging" rel="noreferrer">this one</a> to setup vscode but i think i'm doing something wrong in set it up.</p>
  
  <p>I tried to setup the launch.json both as <strong>python: module</strong> and <strong>python: current file</strong></p>
  
  <p>The problem seems that it doesn't recognize the project structure cause when i run the debug it stopped in an import statement with this error:</p>
  
  <pre><code>Exception has occurred: ImportError
  attempted relative import with no known parent package
  </code></pre>
  
  <p>This is my current launch.json configuration:</p>
  
  <pre><code>"configurations": [
      {
          "name": "Python: local debug",
          "type": "python",
          "request": "launch",
          "program": "${workspaceFolder}/src/topic_service/service/__init__.py",
          "args" : ["--port", "8000"]
      },
  ]
  </code></pre>
  
  <p>I also tried to add a .env file setting PYTHONPATH:</p>
  
  <pre><code>PYTHONPATH=.:${PYTHONPATH}
  </code></pre>
  
  <p>Locally i run the application as follow:</p>
  
  <pre><code>poetry run uvicorn src.main:app --port 8080 --reload
  </code></pre>
  
  <p>Does anyone know how to correctly <strong>setup vscode to debug an uvicorn application</strong>?</p>
  
  <p>Thank you</p>
  
  <p><strong>UPDATE:</strong>
  I also tried what <a href="https://blog.hipolabs.com/remote-debugging-with-vscode-docker-and-pico-fde11f0e5f1c" rel="noreferrer">this article</a> says. the debugger seems to start but nothing happen (no breakpoint is triggered)</p>