博客
关于我
解决jupyter运行pyqt代码内核重启
阅读量:129 次
发布时间:2019-02-27

本文共 611 字,大约阅读时间需要 2 分钟。

在jupyter notebook或者是 Qtconsole下编译运行一个简单的pyqt程序,总是报错:The kernel appears to have died. It will restart automatically.

from PyQt5.QtWidgets import *from PyQt5.QtGui import *from PyQt5.QtCore import *import sysapp = QApplication(sys.argv)window = QWidget();window.show()app.exec_()

这里写图片描述

在网上找了半天原因,终于在一个小角落发现了问题所在。现在记下来。
这是因为jupyter本身也是用pyqt编写的,python同时只能运行一个内核。在上述代码最后一行一下子把内核给停止了,所以就导致了重启。
改成

sys.exit(app.exec_())

这样再运行结束程序是只会结束本程序 不会终止内核 。问题解决。

但是这样也引入了一个新的问题

An exception has occurred, use %tb to see the full traceback

因为这个程序直接调用sys.exit直接终止的 。不过影响不大。

总结:这两个错误都是在IPython交互环境下才会报错,脚本运行时不会报错。如果对报错介意的话 ,就还是使用命令行执行程序吧。

你可能感兴趣的文章
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>