我正在尝试调试使用 FastAPI (uvicorn) 的应用程序 (web api)
我也在使用诗歌并在 vscode 中设置 projev 虚拟环境。
i read this https://fastapi.tiangolo.com/tutorial/debugging/设置 uvicorn 和的教程this one https://code.visualstudio.com/docs/python/debugging设置 vscode 但我认为我在设置它时做错了什么。
我尝试将 launch.json 设置为蟒蛇:模块 and python: 当前文件
问题似乎是它无法识别项目结构,因为当我运行调试时,它在导入语句中停止并出现以下错误:
Exception has occurred: ImportError
attempted relative import with no known parent package
这是我当前的 launch.json 配置:
"configurations": [
{
"name": "Python: local debug",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/topic_service/service/__init__.py",
"args" : ["--port", "8000"]
},
]
我还尝试添加一个 .env 文件设置 PYTHONPATH:
PYTHONPATH=.:${PYTHONPATH}
我在本地运行应用程序如下:
poetry run uvicorn src.main:app --port 8080 --reload
有谁知道如何正确设置 vscode 来调试 uvicorn 应用程序?
谢谢
UPDATE:我也尝试过什么本文 https://blog.hipolabs.com/remote-debugging-with-vscode-docker-and-pico-fde11f0e5f1c说。调试器似乎启动了,但什么也没发生(没有触发断点)