vscode调试python时出现import其他文件夹找不到路径的报错,需要设置正确的working directory (cwd)和PYTHONPATH(env)
{ "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "libs/evaluation/evaluation.py", "console": "integratedTerminal", "justMyCode": true, "cwd": "/xxx/codes/project", "args": [], "env": { "PYTHONPATH": "/xxx/codes/project:${env:PYTHONPATH}" } } ] }
在这个例子中,我们添加了一个
PYTHONPATH
环境变量,它的值被设置为项目根目录的路径。"${env:PYTHONPATH}"
是用来包含原有 PYTHONPATH
环境变量的值,以便将新路径添加到现有的 PYTHONPATH
定义上,而不是替换掉它。注意:在VS Code中,环境变量中的路径使用冒号
:
在Linux和macOS上分隔,而在Windows上使用分号 ;
分隔。- ModuleNotFoundError 文件 vscode import modulemodulenotfounderror文件vscode import modulenotfounderror import_export module import 文件vscode import ctrl modulenotfounderror module named 39 node_modules modules文件vscode modulenotfounderror watchdog module named modulenotfounderror resultlog module pytest modulenotfounderror python3 python module modulenotfounderror module kornia named modulenotfounderror module compat flask