我正在尝试从 github 存储库调试 python 文件pypmu github。当我尝试调试时
apps/pmy.py
我得到了
Exception has occurred: ModuleNotFoundError
No module named 'synchrophasor'
File "D:\BTP\pypmu\synchrophasor\pmu.py", line 10, in <module>
from synchrophasor.frame import *
ModuleNotFoundError: No module named 'synchrophasor'
如何确保 python 在调试活动文件之前首先解释依赖文件?
我尝试更改 .vscode/launch.json
中的
args但无法弄清楚任何事情?
确保调试时正确加载依赖文件中的 Python 模块。
launch.json
以包含 env
设置,将项目根目录添加到 PYTHONPATH,以便 Python 可以找到同步相量模块。这是一个例子:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug apps/pmy.py",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/apps/pmy.py", //specifies the file you want to debug
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceFolder}" //add the workspace folder to the PYTHONPATH.
},
"justMyCode": false
}
]
}
我假设你的项目结构如下:
pypmu/
├── apps/
│ └── pmy.py
├── synchrophasor/
│ ├── __init__.py
│ ├── frame.py
│ └── pmu.py
└── .vscode/
└── launch.json
from synchrophasor.frame import *