vscode中使用jupyter调用%matplotlib qt报错问题

%matplotlib

  1. 调用%matplotlib qt可以在jupyter ipykernel中弹出外置画图显示窗口
  2. 调用%matplotlib inline 可以在jupyter ipykernel中内画图

遇到问题

当我调用%matplotlib qt想在外部画图遇到下面错误

Info 10:14:44: Raw session started and connected
Started kernel Python 3.8.10 64-bit
Info 10:14:44: Finished connecting 2d9b5bfb-79b0-4d36-9289-fe0664f7df80
Info 10:14:44: Executing silently Code (idle) = import sys\nprint(sys.executable)
Info 10:14:45: Executing silently Code (completed) = import sys\nprint(sys.executable)
Info 10:14:45: UpdateWorkingDirectoryAndPath in Kernel
Info 10:14:45: Executing silently Code (idle) = import site\nsite.addsitedir(site.getusersitepackages())\nimport os\nimport sys\n%cd "/home/ubuntu/rl-ui
Info 10:14:45: Executing silently Code (completed) = import site\nsite.addsitedir(site.getusersitepackages())\nimport os\nimport sys\n%cd "/home/ubuntu/rl-ui
Info 10:14:45: Waiting for idle on (kernel): 16c55f0a-4aad-4cb9-b5b3-bfeafa9be4dd -> idle
Info 10:14:45: Finished waiting for idle on (kernel): 16c55f0a-4aad-4cb9-b5b3-bfeafa9be4dd -> idle
Info 10:14:45: Executing silently Code (idle) = __file__ = '/home/ubuntu/rl-uitls/M/TD3/exp2/main.py'
Info 10:14:45: Executing silently Code (completed) = __file__ = '/home/ubuntu/rl-uitls/M/TD3/exp2/main.py'
Info 10:14:45: Adding hash for 1 = 015a0e4fe271 with 2 lines
Info 10:14:45: Cell 1 executed with state Success
Info 10:14:45: Adding hash for 2 = 37e1a253019d with 15 lines
Info 10:14:46: Executing silently Code (busy) = # Query Jupyter server for the info about a dataframe\nimport json as _VSCODE_json\nimport builtins as
Info 10:14:46: Cell 2 executed with state Success
Info 10:14:46: Executing silently Code (completed) = # Query Jupyter server for the info about a dataframe\nimport json as _VSCODE_json\nimport builtins as
Info 10:14:46: Executing silently Code (idle) = import builtins\n_rwho_ls = %who_ls\nbuiltins.print(_VSCODE_getVariableTypes(_rwho_ls))
Info 10:14:46: Executing silently Code (completed) = import builtins\n_rwho_ls = %who_ls\nbuiltins.print(_VSCODE_getVariableTypes(_rwho_ls))
Info 10:14:47: Adding hash for 3 = c234e25135bc with 64 lines
Info 10:14:53: Cell 3 executed with state Success
Info 10:14:55: Adding hash for 4 = fe7ef7b69c60 with 16 lines
Info 10:14:59: Disposing kernel .jvsc74a57bd0916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1./bin/python3./bin/python3.-m#ipykernel_launcher for notebook vscode-interactive:Interactive-1.interactive due to selection of another kernel or closing of the notebook
Info 10:14:59: Dispose kernel file:///home/ubuntu/rl-uitls/M/TD3/exp2/main.py
Info 10:14:59: Dispose Kernel process
Info 10:14:59: Notebook Closed vscode-interactive:Interactive-1.interactive
Info 10:14:59: Closing interactive window: vscode-interactive:Interactive-1.interactive
Info 10:14:59: Cancel all remaining cells due to dead kernel
Info 10:14:59: Cancel pending cells
Info 10:14:59: Cell 4 executed with state Idle
Info 10:15:35: Creating controller for interactive with interpreter /bin/python3
Info 10:15:35: Starting interactive window with controller ID ms-toolsai.jupyter/.jvsc74a57bd0916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1./bin/python3./bin/python3.-m#ipykernel_launcher (Interactive)
Info 10:15:35: Setting setActiveController for vscode-interactive:Interactive-1.interactive
Info 10:15:35: Creating controller for interactive with interpreter /bin/python3
Info 10:15:35: TargetController found ID: .jvsc74a57bd0916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1./bin/python3./bin/python3.-m#ipykernel_launcher (Interactive) for document vscode-interactive:Interactive-1.interactive
Info 10:15:35: Setting controller affinity for vscode-interactive:Interactive-1.interactive .jvsc74a57bd0916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1./bin/python3./bin/python3.-m#ipykernel_launcher (Interactive)
Info 10:15:36: Starting Notebook in kernel.ts id = .jvsc74a57bd0916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1./bin/python3./bin/python3.-m#ipykernel_launcher
Info 10:15:36: Creating raw notebook for vscode-interactive:Interactive-1.interactive
Info 10:15:36: Getting preferred kernel for vscode-interactive:Interactive-1.interactive
Info 10:15:36: Computing working directory vscode-interactive:Interactive-1.interactive
Info 10:15:36: Starting raw kernel Python 3.8.10 64-bit for interpreter /bin/python3
Info 10:15:36: installMissingDependencies /bin/python3
Info 10:15:36: IPyKernel found previously in this environment /bin/python3
Info 10:15:36: Kernel launching with ports 9000,9001,9002,9003,9004. Start port is 9000
Info 10:15:36: Process Execution: > /bin/python3 -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
> /bin/python3 -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
Info 10:15:36: Process Execution: > /bin/python3 -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"2ce0cb71-1389-47c6-b1eb-4ee3fd208265" --shell=9002 --transport="tcp" --iopub=9004 --f=/tmp/tmp-1721057Vnptc1MRARS9.json
> /bin/python3 -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"2ce0cb71-1389-47c6-b1eb-4ee3fd208265" --shell=9002 --transport="tcp" --iopub=9004 --f=/tmp/tmp-1721057Vnptc1MRARS9.json
Info 10:15:36: Process Execution: cwd: ~/rl-uitls/M/TD3/exp2
cwd: ~/rl-uitls/M/TD3/exp2
Info 10:15:36: ipykernel version 6.0.3 for /bin/python3
Info 10:15:36: ipykernel location ~/.local/lib/python3.8/site-packages/ipykernel/__init__.py for /bin/python3
Warn 10:15:36: StdErr from Kernel Process /home/ubuntu/.local/lib/python3.8/site-packages/traitlets/traitlets.py:2196: FutureWarning: Supporting extra quotes around Unicode is deprecated in traitlets 5.0. Use 'hmac-sha256' instead of '"hmac-sha256"' – or use CUnicode.
  warn(

Warn 10:15:36: StdErr from Kernel Process /home/ubuntu/.local/lib/python3.8/site-packages/traitlets/traitlets.py:2151: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use '2ce0cb71-1389-47c6-b1eb-4ee3fd208265' instead of 'b"2ce0cb71-1389-47c6-b1eb-4ee3fd208265"'.
  warn(

Info 10:15:36: Kernel Output: NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.

To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.

To read more about this, see https://github.com/ipython/ipython/issues/2049


To connect another client to this kernel, use:
    --existing /tmp/tmp-1721057Vnptc1MRARS9.json

Info 10:15:36: Raw session started and connected
Started kernel Python 3.8.10 64-bit
Info 10:15:36: Finished connecting 2d9b5bfb-79b0-4d36-9289-fe0664f7df80
Info 10:15:36: Executing silently Code (idle) = import sys\nprint(sys.executable)
Info 10:15:36: Executing silently Code (completed) = import sys\nprint(sys.executable)
Info 10:15:36: UpdateWorkingDirectoryAndPath in Kernel
Info 10:15:36: Executing silently Code (idle) = import site\nsite.addsitedir(site.getusersitepackages())\nimport os\nimport sys\n%cd "/home/ubuntu/rl-ui
Info 10:15:36: Executing silently Code (completed) = import site\nsite.addsitedir(site.getusersitepackages())\nimport os\nimport sys\n%cd "/home/ubuntu/rl-ui
Info 10:15:36: Waiting for idle on (kernel): 88ecb34f-3e1e-41c9-b407-bc869abbabe2 -> idle
Info 10:15:36: Finished waiting for idle on (kernel): 88ecb34f-3e1e-41c9-b407-bc869abbabe2 -> idle
Info 10:15:36: Executing silently Code (idle) = __file__ = '/home/ubuntu/rl-uitls/M/TD3/exp2/main.py'
Info 10:15:36: Executing silently Code (completed) = __file__ = '/home/ubuntu/rl-uitls/M/TD3/exp2/main.py'
Info 10:15:37: Adding hash for 1 = 9704f7e71b43 with 19 lines
Info 10:15:38: Cell 1 executed with state Success
Error 10:15:38: Disposing session as kernel process died ExitCode: undefined, Reason: /home/ubuntu/.local/lib/python3.8/site-packages/traitlets/traitlets.py:2196: FutureWarning: Supporting extra quotes around Unicode is deprecated in traitlets 5.0. Use 'hmac-sha256' instead of '"hmac-sha256"' – or use CUnicode.
  warn(
/home/ubuntu/.local/lib/python3.8/site-packages/traitlets/traitlets.py:2151: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use '2ce0cb71-1389-47c6-b1eb-4ee3fd208265' instead of 'b"2ce0cb71-1389-47c6-b1eb-4ee3fd208265"'.
  warn(

Info 10:15:38: Dispose Kernel process
Error 10:15:38: Raw kernel process exited code: undefined

解决

我尝试了重装qt5和其他很多方法,然而并没有作用。其实问题来自我把%matplotlib qt这语句放在了代码中间并和其他代码运行在同一个块里面,把%matplotlib qt放在代码首行并单独运行就不会出现这种问题。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值