当前位置:   article > 正文

vscode 调试环境工作路径与实际工作路径不一致问题_vscode终端路径不是工作区

vscode终端路径不是工作区

vscode 调试环境工作路径与实际工作路径不一致问题

问题描述

命令行运行与在vscode调试环境运行同一个脚本,后者会报额外的no such file or directory错误

问题定位

在debug的报错行前加入一下代码,查看调试环境的工作路径:

cur_dir = os.getcwd()
print(cur_dir)
  • 1
  • 2

发现当前工作路径与实际需要的工作路径不符(通常是在更外层,这个错误一般也是因为在脚本中使用相对路径导致的)

问题解决

打开调试配置文件(debug launch.json),修改或新增cwd字段,进行工作路径指定(即替换成你当前需要的工作路径)

"version": "0.2.0",
"Configurations":[
	{
		...
		"cwd": "/your/current/workspace",
		...
	}
	]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

或者使用模块执行配置:将"program": "${file}"字段换成"module":xxx.xxx.xxx字段,相当于以python -m方式执行

"configurations": [
        {
            "name": "module python",
            "type": "python",
            "request": "launch",
            "cwd": "/your/current/workspace",
            //"program": "${file}",
            "module": "your.module.path",
            "console": "integratedTerminal",
            "justMyCode": true
        },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/967069
推荐阅读
相关标签
  

闽ICP备14008679号