我正在尝试从一个目录级别向上导入 python。
import sys
sys.path.append('..')
from cn_modules import exception
当我尝试执行 Run Build Task 时,我从 VSCode 收到错误消息:
ImportError:没有名为 cn_modules 的模块
相同的代码在终端 (python) 中没有任何错误。
当我尝试从 VSCode Run Build task运行它时,我遇到了这个问题。
关于这里有什么问题的任何线索?
已经安静了一段时间,但无法解决此问题,不胜感激。
注意:这在我也使用 vscode 进行调试时有效。下面是我对 launch.json 和 tasks.json 的配置
启动.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Console App",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"externalConsole": true,
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
],
"env": {},
"envFile": "${workspaceRoot}/.env",
"console":"integratedTerminal",
"pythonPath": "${config:python.pythonPath}"
}
]
}
任务.json
{
"version": "0.1.0",
"command": "/usr/bin/python",
"isShellCommand": true,
"args": ["${file}"],
"showOutput": "always",
"env": {},
"envFile": "${workspaceRoot}/.env",
"pythonPath": "${config:python.pythonPath}"
}