Reputation: 51
I'm using Remote-Containers to debug an FastApi app. The container has all the dependecies installed. When I try to debug using the vscode debugger I got the error No module named uvicorn
. But if I run uvicorn api.main:app
it works.
/usr/bin/env /usr/bin/python3 /Users/juracylopes/.vscode/extensions/ms-python.python-2022.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 59746 -- -m uvicorn api.main:app /Library/Developer/CommandLineTools/usr/bin/python3: No module named uvicorn
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"api.main:app"
],
"jinja": true,
"justMyCode": true
}
]
} ```
Upvotes: 5
Views: 8028
Reputation: 41
Perhaps you've installed uvicorn in a virtual environment in your workspace? In that case, the Python that VSCode is running for your debugging session might not be referencing your venv.
I'm using python -m venv .venv
to create my virtual environment, so my venv Python is at ${workspaceFolder}/.venv/bin/python
.
Consider adding this to your project .vscode/settings.json:
{
"python.pythonPath": "${workspaceFolder}/.venv/bin/python"
}
And then reloading your session to enable remote debugging via a module
with your session referencing the virtual environment.
Reference:
How to add virtual environment to VSCode launch JSON
Upvotes: 0