VScode中debug模式下,报错:ModuleNotFoundError: No module named ‘xxx’
问题:终端命令可以正常运行项目程序,但是转为launch.json配置后采用vscode debug模式下运行报错
修改launch.json, 新增‘env’ 和 ‘envFile’ 变量即可解决
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
/
"env": {"PYTHONPATH":"${workspaceRoot}"},
"envFile":"${workspaceFolder}/.env"
/
}
]
}