首页 > 解决方案 > Python QApplication分段错误

问题描述

我正在尝试在 Ubuntu 机器上运行 pyt5,但即使是基本示例也失败了:

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize    

class HelloWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(640, 480))    
        self.setWindowTitle("Hello world") 

        centralWidget = QWidget(self)          
        self.setCentralWidget(centralWidget)   

        gridLayout = QGridLayout(self)     
        centralWidget.setLayout(gridLayout)  

        title = QLabel("Hello World from PyQt", self) 
        title.setAlignment(QtCore.Qt.AlignCenter) 
        gridLayout.addWidget(title, 0, 0)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv) #<--crash after this line
    mainWin = HelloWindow()
    mainWin.show()
    sys.exit( app.exec_())

尝试构建 QApplication 对象时,我得到:

进程以退出代码 139 结束(被信号 11 中断:SIGSEGV)

从 PyCharm(终端)外部运行相同的文件会产生:

分段错误(核心转储)

我在 Ubuntu 16.04.5 LTS 上使用 Python 3.6.5

标签: pythonpyqt5python-3.6

解决方案


推荐阅读