1. 问题描述
VS Code执行Python,出现Exception has occurred: ModuleNotFoundError
,错误内容如下。
Exception has occurred: ModuleNotFoundError
No module named 'code_L_PSD_cal'
File "E:\09-code\06-Turbulent_spectrum02\code_L_PSD_cal\TurSpecLPSDcalMain.py", line 22, in <module>
from code_L_PSD_cal.TI3DTranBri import Trans3D
如下图所示:
2. 解决办法
2.1 打开 launch.json
文件
-
方案一:进入调试界面,点击配置按钮。
-
方案二:在文件浏览界面,进入工作目录–>.vscode目录下面
2.2 配置 launch.json
文件,
配置项新增
"env": {"PYTHONPATH":"${workspaceRoot}"}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"env": {"PYTHONPATH":"${workspaceRoot}"}
}
]
}