问题描述:
文件的目录为:
E:.
├─.vscode
| ├─lauch.json
│ └─setting.json
├─contract_trader
│ ├─…
│ └─myAccountKey.py
└─spot_trader
├─customized
| ├─…
│ └─trader_customized_by_hour.py
├─huobi
│ ├─…
│ ├─constant
│ ├─demo_service
│ ├─exception
│ ├─impl
│ ├─model
├─performance
└─tests
运行的文件是./spot_trader/customized/trader_customized_by_hour.py
里面引用的模块在./spot_trader/huobi/model/下面
始终提示无法找到huobi里的模块
解决办法是:
在.vscode里修改运行配置文件launch.json如下:
增加键值对:
"env": {
"PYTHONPATH": "${workspaceRoot}/spot_trader"
},
同理,如果要引用contract_trader里面的myAccountKey.py,也是修改env关键字的内容,增加以下值:
${workspaceRoot}/contract_trader
多个env的值之间用分号" ; "隔开。
完整配置如下:
{
// 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: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"env": {
"PYTHONPATH": "${workspaceRoot}/spot_trader;${workspaceRoot}/contract_trader"
},
"console": "integratedTerminal"
},
]
}