最近在用VSCode去调试Python代码,结果时不时的会出错:调试适配器进程意外终止 (Cannot read property 'style' of undefined {"command":"runInTerminal","arguments":{"kind":"integrated","title":"Python Debug Console","cwd":"/Users/crifan/dev/dev_root/company/xxx","args":["/usr/local/bin/python3","/Users/crifan/.vscode/extensions/ms-python.python-2018.11.0/pythonFiles/experimental/ptvsd_launcher.py","--default","--client","--host","localhost","--port","59599","/Users/crifan/dev/dev_root/yyy.py"],"env":{"PYTHONIOENCODING":"UTF-8","PYTHONUNBUFFERED":"1"}},"type":"request","seq":2})
刚才又出现同样错误了:
在刚调试完毕后,再去(F5)调试,结果就报错了。
之前也遇到类似问题,关闭VSCode再重启就好了。
现在希望彻底解决此问题。
VSCode debug python Cannot read property ‘style’ of undefined {“command”:”runInTerminal”
“Support for removing variables from the environment
The runInTerminal request is used by a debug adapter to launch a debug target in an integrated or external terminal. One parameter to the request is the set of environment variables to pass to the debug target. In this release, null has been added to the environment variable’s value type with the semantics “remove the environment variable from the environment before launching the target”.”
感觉是配置问题,去看看
注意到此处的调试是没有配置:
所以需要去加一个默认的配置?
加了后是: {
"name": "Python: Terminal (integrated)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
发现和现有的一样:
所以还是去删除掉新加的:
保留之前的: {
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
然后切换到当前python文件,再去调试:
问题依旧:
调试适配器进程意外终止 (Cannot read property 'style' of undefined {"command":"runInTerminal","arguments":{"kind":"integrated","title":"Python Debug Console","cwd":"/Users/crifan/dev/dev_root/xxx","args":["/usr/local/bin/python3","/Users/crifan/.vscode/extensions/ms-python.python-2018.11.0/pythonFiles/experimental/ptvsd_launcher.py","--default","--client","--host","localhost","--port","65367","/Users/crifan/dev/dev_root/xxx.py"],"env":{"PYTHONIOENCODING":"UTF-8","PYTHONUNBUFFERED":"1"}},"type":"request","seq":2})
感觉python路径不对啊:
/usr/local/bin/python3
不是我现在选择的:
发现判断错了,就是当前选的python版本。
参考:{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
-》
此处想要去ll查看文件都挂了:
算了,重启VSCode再说。
删除.vscode目录:
重新新建VSCode项目:
再去调试是否可以调试:
去选择python版本
然后就可以正常调试了:
【总结】
暂时还是没有彻底解决掉,为何会报错:调试适配器进程意外终止 (Cannot read property 'style' of undefined {"command":"runInTerminal","arguments":{"kind":"integrated","title":"Python Debug Console","cwd":"/Users/crifan/dev/dev_root/xxx","args":["/usr/local/bin/python3","/Users/crifan/.vscode/extensions/ms-python.python-2018.11.0/pythonFiles/experimental/ptvsd_launcher.py","--default","--client","--host","localhost","--port","59599","/Users/crifan/dev/dev_root/xxx.py"],"env":{"PYTHONIOENCODING":"UTF-8","PYTHONUNBUFFERED":"1"}},"type":"request","seq":2})
而只是重启VSCode或删除.vscode,重建项目,重新选择Python解析器,添加基本的debug配置,才能正常调试。
【后记】
但是此处郁闷的是,几秒前可以调试,但是接着重新调试就不行了
VSCode调试python 调试适配器进程意外终止
“卸载python调试插件以后重装插件,就解决了”
现在大意像是明白了:
Python的调试的插件,对于:{"command":"runInTerminal","arguments":{"kind":"integrated","title":"Python Debug Console","cwd":"/Users/crifan/dev/dev_root/xxx","args":["/usr/local/opt/python/bin/python3.6","/Users/crifan/.vscode/extensions/ms-python.python-2018.11.0/pythonFiles/experimental/ptvsd_launcher.py","--default","--client","--host","localhost","--port","56965","/Users/crifan/dev/dev_root/xxx.py"],"env":{"PYTHONIOENCODING":"UTF-8","PYTHONUNBUFFERED":"1"}},"type":"request","seq":2}
-》{
"command": "runInTerminal",
"arguments": {
"kind": "integrated",
"title": "Python Debug Console",
"cwd": "/Users/crifan/dev/dev_root/xxx",
"args": ["/usr/local/opt/python/bin/python3.6", "/Users/crifan/.vscode/extensions/ms-python.python-2018.11.0/pythonFiles/experimental/ptvsd_launcher.py", "--default", "--client", "--host", "localhost", "--port", "56965", "/Users/crifan/dev/dev_root/xxx.py"],
"env": {
"PYTHONIOENCODING": "UTF-8",
"PYTHONUNBUFFERED": "1"
}
},
"type": "request",
"seq": 2
}
这种(类型的)配置,不认,无法识别。
然后才报错的。
此处再去确认python是没问题的:➜ 测试 git:(master) ✗ ll /usr/local/opt/python/bin/python3.6
lrwxr-xr-x 1 crifan admin 57B 12 19 2017 /usr/local/opt/python/bin/python3.6 -> ../Frameworks/Python.framework/Versions/3.6/bin/python3.6
突然发现一个貌似可行的办法:
关闭掉当前的Terminal终端,然后会重新显示一个新的终端
然后就可以正常调试了:
-》推测是之前的,此处调试报错时,终端已经出问题了,导致影响了调试。
【总结】
对于VSCode的python调试,突然会无法调试,报错:调试适配器进程意外终止 (Cannot read property 'style' of undefined {"command":"runInTerminal","arguments":{"kind":"integrated"...
原因:未知
解决方案:
后来经过几次实际测试,我这个办法是可以解决问题的:
点击VSCode的 垃圾箱的那个按钮删除掉当前Terminal终端
然后重新F5开始调试,会自动新生成新的Terminal终端
-》这样就可以正常继续调试了。
-》看来问题是可能是之前的终端有问题而引起的。