最新消息:20181230 VPS服务器已从Linode换到腾讯云香港,主题仍用朋友推荐的大前端D8

【已解决】VSCode调试Python出错:调试适配器进程意外终止Cannot read property ‘style’ of undefined

Python crifan 322浏览 0评论

最近在用VSCode去调试Python代码,结果时不时的会出错:

<code>调试适配器进程意外终止 (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})
</code>

刚才又出现同样错误了:

在刚调试完毕后,再去(F5)调试,结果就报错了。

之前也遇到类似问题,关闭VSCode再重启就好了。

现在希望彻底解决此问题。

VSCode debug python Cannot read property ‘style’ of undefined {“command”:”runInTerminal”

VSCode调试python Cannot read property ‘style’ of undefined {“command”:”runInTerminal”

Visual Studio Code November 2017

“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”.”

Please support “console” Property in launch.json · Issue #843 · Microsoft/vscode-go

感觉是配置问题,去看看

注意到此处的调试是没有配置:

所以需要去加一个默认的配置?

加了后是:

<code>    {
      "name": "Python: Terminal (integrated)",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    },
</code>

发现和现有的一样:

所以还是去删除掉新加的:

保留之前的:

<code>    {
      "name": "Python: Current File (Integrated Terminal)",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    },
</code>

然后切换到当前python文件,再去调试:

问题依旧:

<code>调试适配器进程意外终止 (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})
</code>

感觉python路径不对啊:

/usr/local/bin/python3

不是我现在选择的:

发现判断错了,就是当前选的python版本。

参考:

<code>{
  // 使用 IntelliSense 了解相关属性。
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
</code>

-》

Debugging in Visual Studio Code

此处想要去ll查看文件都挂了:

算了,重启VSCode再说。

删除.vscode目录:

重新新建VSCode项目:

再去调试是否可以调试:

去选择python版本

然后就可以正常调试了:

【总结】

暂时还是没有彻底解决掉,为何会报错:

<code>调试适配器进程意外终止 (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})
</code>

而只是重启VSCode或删除.vscode,重建项目,重新选择Python解析器,添加基本的debug配置,才能正常调试。

【后记】

但是此处郁闷的是,几秒前可以调试,但是接着重新调试就不行了

VSCode调试python 调试适配器进程意外终止

解决Visual Stdio Code 调试时显示“调试适配器进程已意外终止” – 小米的蝉的博客 – CSDN博客

vscode运行python代码出现运行不了货者“调试适配器进程已意外终止”怎么办?-CSDN问答

“卸载python调试插件以后重装插件,就解决了”

【DEBUG笔记】VSCode调试python提示“vscode调试适配器已意外终止” – orangecsy的博客 – CSDN博客

调试适配器进程已意外终止 · Issue #45496 · Microsoft/vscode

连续多次调试后出现无法保存修改后文件的问题 · Issue #1 · actboy168/vscode-lua-debug

调试适配器进程已意外终止 · Issue #38684 · Microsoft/vscode

如何在 VScode 中配置 Python 的交互式命令环境 – V2EX

现在大意像是明白了:

Python的调试的插件,对于:

<code>{"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}
</code>

-》

<code>{
  "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
}
</code>

这种(类型的)配置,不认,无法识别。

然后才报错的。

此处再去确认python是没问题的:

<code>➜  测试 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 -&gt; ../Frameworks/Python.framework/Versions/3.6/bin/python3.6
</code>

突然发现一个貌似可行的办法:

关闭掉当前的Terminal终端,然后会重新显示一个新的终端

然后就可以正常调试了:

-》推测是之前的,此处调试报错时,终端已经出问题了,导致影响了调试。

【总结】

对于VSCode的python调试,突然会无法调试,报错:

<code>调试适配器进程意外终止 (Cannot read property 'style' of undefined {"command":"runInTerminal","arguments":{"kind":"integrated"...
</code>

原因:未知

解决方案:

后来经过几次实际测试,我这个办法是可以解决问题的:

点击VSCode的 垃圾箱的那个按钮删除掉当前Terminal终端

然后重新F5开始调试,会自动新生成新的Terminal终端

-》这样就可以正常继续调试了。

-》看来问题是可能是之前的终端有问题而引起的。

转载请注明:在路上 » 【已解决】VSCode调试Python出错:调试适配器进程意外终止Cannot read property ‘style’ of undefined

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
55 queries in 0.113 seconds, using 9.98MB memory