使用Qt寫了個窗口,運行報錯,無法正常運行python程序,獲得的報錯信息如下:
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
經過仔細查看發現是在使用Qt模塊導入了Qt4和Qt5兩個模塊(存在重合的部分),部分代碼如下:
//Qt5
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QFont, QBrush
from PyQt5.QtWidgets import QTableWidget
from PyQt4 import Qt //QT4
class Ui_TabWidget(object):
def setupUi(self,TabWidget):
TabWidget.setObjectName("TabWidget")
TabWidget.resize(962, 618)
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.lineEdit = QtWidgets.QLineEdit(self.tab)
self.lineEdit.setGeometry(QtCore.QRect(10, 20, 291, 31))
self.lineEdit.setObjectName("lineEdit")
self.label = QtWidgets.QLabel(self.tab)
self.label.setGeometry(QtCore.QRect(310, 30, 54, 21))
self.label.setObjectName("label")
self.fontComboBox = QtWidgets.QFontComboBox(self.tab)
self.fontComboBox.setGeometry(QtCore.QRect(350, 20, 161, 31))
self.fontComboBox.setObjectName("fontComboBox")
self.pushButton = QtWidgets.QPushButton(self.tab)
......
我嘗試着去除Qt4和Qt5重合導入的模塊,運行發現可以成功,自以為這就是失敗的原因了,為了放心我又單獨測試了一下導入Qt4,代碼如下:
# !/usr/bin/env python
# -*- encoding:utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui, QtWidgets
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('helloworld')
w.show()
sys.exit(app.exec_())
結果運行如下:
/usr/bin/python2.7 ~/helloworld
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
如此可以發現,不是由於重復導入模塊而導致運行失敗的,可以確認是由於Qt4模塊自身出現了異常,猜測可能是由於sip導致Qt4模塊的異常,然后發現我並沒有PyQt4_gpl_x11,為了驗證,我重新安裝了PyQt4來驗證,Ubuntu中安裝配置過程如下:
1)安裝sip
地址:http://www.riverbankcomputing.co.uk/software/sip/download
cd sip-4.19.3/
sudo python configure.py
sudo make install
2)安裝Qt4的依賴
sudo apt-get install qt4-dev-tools qt4-doc qt4-qtconfig qt4-demos qt4-designer
sudo apt-get install libqwt5-qt4 libqwt5-qt4-dev
3)安裝PyQt4
cd PyQt4_gpl_x11-4.12.1
sudo python configure.py
sudo make
sudo make install
重新運行,成功運行!!!