导入

时间:2017-10-17 16:53:31

标签: python qt pyqt segmentation-fault pyqt5

从PyQt5导入Qt会产生分段错误。

$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5 import Qt
[1]    7667 segmentation fault (core dumped)  python

使用GDB运行会提供更多信息。

$ gdb -ex r --args python -c "from PyQt5 import Qt"
...
Starting program: /usr/bin/python -c from\ PyQt5\ import\ Qt
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
strlen () at ../sysdeps/x86_64/strlen.S:106
106 ../sysdeps/x86_64/strlen.S: No such file or directory.

编辑:出于版本控制的原因,我不得不从源代码编译PyQt5。这是来自PyQt配置脚本的full output。以下是缩写版本。

$ python configure.py --verbose --qmake=/home/jeff/Qt/5.9.2/gcc_64/bin/qmake
Querying qmake about your Qt installation...
Determining the details of your Qt installation...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_QtCore.mk cfgtest_QtCore.pro
Info: creating stash file /home/jeff/Downloads/PyQt5_gpl-5.9/.qmake.stash
make -f cfgtest_QtCore.mk
g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_CORE_LIB -I. -I../../Qt/5.9.2/gcc_64/include -I../../Qt/5.9.2/gcc_64/include/QtCore -I. -I../../Qt/5.9.2/gcc_64/mkspecs/linux-g++ -o cfgtest_QtCore.o config-tests/cfgtest_QtCore.cpp
g++ -Wl,-O1 -Wl,-rpath,/home/jeff/Qt/5.9.2/gcc_64/lib -o cfgtest_QtCore cfgtest_QtCore.o   -L/home/jeff/Qt/5.9.2/gcc_64/lib -lQt5Core -lpthread 
./cfgtest_QtCore cfgtest_QtCore.out
This is the GPL version of PyQt 5.9 (licensed under the GNU General Public
License) for Python 2.7.12 on linux2.

Type 'L' to view the license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.

Do you accept the terms of the license? yes
Found the license file pyqt-gpl.sip.

Checking to see if the QtGui module should be built...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_QtGui.mk cfgtest_QtGui.pro
make -f cfgtest_QtGui.mk
g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../Qt/5.9.2/gcc_64/include -I../../Qt/5.9.2/gcc_64/include/QtGui -I../../Qt/5.9.2/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I../../Qt/5.9.2/gcc_64/mkspecs/linux-g++ -o cfgtest_QtGui.o config-tests/cfgtest_QtGui.cpp
g++ -Wl,-O1 -Wl,-rpath,/home/jeff/Qt/5.9.2/gcc_64/lib -o cfgtest_QtGui cfgtest_QtGui.o   -L/home/jeff/Qt/5.9.2/gcc_64/lib -lQt5Gui -lQt5Core -lGL -lpthread 
./cfgtest_QtGui cfgtest_QtGui.out

...

Checking to see if the QtWebKit module should be built...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_QtWebKit.mk cfgtest_QtWebKit.pro
Project ERROR: Unknown module(s) in QT: webkit

Checking to see if the QtWebKitWidgets module should be built...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_QtWebKitWidgets.mk cfgtest_QtWebKitWidgets.pro
Project ERROR: Unknown module(s) in QT: webkitwidgets

...

Checking to see if the QAxContainer module should be built...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_QAxContainer.mk cfgtest_QAxContainer.pro
Project ERROR: Unknown module(s) in QT: axcontainer

...

Checking to see if the QtMacExtras module should be built...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_QtMacExtras.mk cfgtest_QtMacExtras.pro
Project ERROR: Unknown module(s) in QT: macextras

...

Checking to see if the QtWinExtras module should be built...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_QtWinExtras.mk cfgtest_QtWinExtras.pro
Project ERROR: Unknown module(s) in QT: winextras

...

Checking to see if the Enginio module should be built...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_Enginio.mk cfgtest_Enginio.pro
Project ERROR: Unknown module(s) in QT: enginio

...

Checking to see if the QtWebEngine module should be built...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -o cfgtest_QtWebEngine.mk cfgtest_QtWebEngine.pro
make -f cfgtest_QtWebEngine.mk
g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WEBENGINE_LIB -DQT_WEBENGINECORE_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_WEBCHANNEL_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_POSITIONING_LIB -DQT_CORE_LIB -I. -I../../Qt/5.9.2/gcc_64/include -I../../Qt/5.9.2/gcc_64/include/QtWebEngine -I../../Qt/5.9.2/gcc_64/include/QtWebEngineCore -I../../Qt/5.9.2/gcc_64/include/QtQuick -I../../Qt/5.9.2/gcc_64/include/QtGui -I../../Qt/5.9.2/gcc_64/include/QtWebChannel -I../../Qt/5.9.2/gcc_64/include/QtQml -I../../Qt/5.9.2/gcc_64/include/QtNetwork -I../../Qt/5.9.2/gcc_64/include/QtPositioning -I../../Qt/5.9.2/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I../../Qt/5.9.2/gcc_64/mkspecs/linux-g++ -o cfgtest_QtWebEngine.o cfgtest_QtWebEngine.cpp
cfgtest_QtWebEngine.cpp: In function ‘int main(int, char**)’:
cfgtest_QtWebEngine.cpp:5:17: warning: unused variable ‘v’ [-Wunused-variable]
    const char *v = QTWEBENGINE_VERSION_STR;
                ^
g++ -Wl,-O1 -Wl,-rpath,/home/jeff/Qt/5.9.2/gcc_64/lib -Wl,-rpath-link,/home/jeff/Qt/5.9.2/gcc_64/lib -o cfgtest_QtWebEngine cfgtest_QtWebEngine.o   -L/home/jeff/Qt/5.9.2/gcc_64/lib -lQt5WebEngine -lQt5WebEngineCore -lQt5Quick -lQt5Gui -lQt5WebChannel -lQt5Qml -lQt5Network -lQt5Positioning -lQt5Core -lGL -lpthread 
Checking to see if the dbus support module should be built...
pkg-config --cflags-only-I --libs dbus-1
Qt v5.9.2 is being used.
The qmake executable is /home/jeff/Qt/5.9.2/gcc_64/bin/qmake.
Qt is built as a shared library.
SIP 4.19.3 is being used.
The sip executable is /usr/bin/sip.
These PyQt5 modules will be built: QtCore, QtGui, QtHelp, QtMultimedia,
QtMultimediaWidgets, QtNetwork, QtOpenGL, QtPrintSupport, QtQml, QtQuick,
QtSql, QtSvg, QtTest, QtWidgets, QtXml, QtXmlPatterns, QtDesigner, QtDBus,
_QOpenGLFunctions_2_0, _QOpenGLFunctions_2_1, _QOpenGLFunctions_4_1_Core,
QtSensors, QtSerialPort, QtX11Extras, QtBluetooth, QtPositioning,
QtQuickWidgets, QtWebSockets, QtWebChannel, QtWebEngineWidgets, QtLocation,
QtNfc, QtWebEngineCore, QtWebEngine.
The PyQt5 Python package will be installed in /usr/lib/python2.7/dist-packages.
PyQt5 is being built with generated docstrings.
PyQt5 is being built with 'protected' redefined as 'public'.
The Designer plugin will be installed in
/home/jeff/Qt/5.9.2/gcc_64/plugins/designer.
The qmlscene plugin will be installed in
/home/jeff/Qt/5.9.2/gcc_64/plugins/PyQt5.
The dbus support module will be installed in
/usr/local/lib/python2.7/dist-packages/dbus/mainloop.
The PyQt5 .sip files will be installed in /usr/share/sip/PyQt5.
pyuic5, pyrcc5 and pylupdate5 will be installed in /usr/bin.
The interpreter used by pyuic5 is /usr/bin/python.
Generating the C++ source for the QtCore module...
/usr/bin/sip -w -f -x VendorID -t WS_X11 -t Qt_5_9_2 -x Py_v3 -B Qt_6_0_0 -P -o -c /home/jeff/Downloads/PyQt5_gpl-5.9/QtCore -I sip -I /home/jeff/Downloads/PyQt5_gpl-5.9/sip /home/jeff/Downloads/PyQt5_gpl-5.9/sip/QtCore/QtCoremod.sip
Embedding sip flags...

Generating the .pro file for the QtCore module...
Generating the C++ source for the QtGui module...
/usr/bin/sip -w -f -x VendorID -t WS_X11 -t Qt_5_9_2 -x Py_v3 -B Qt_6_0_0 -P -o -c /home/jeff/Downloads/PyQt5_gpl-5.9/QtGui -I sip -I /home/jeff/Downloads/PyQt5_gpl-5.9/sip /home/jeff/Downloads/PyQt5_gpl-5.9/sip/QtGui/QtGuimod.sip

...

Generating the .pro file for the pyrcc module...
Generating the C++ source for the Qt module...
/usr/bin/sip -w -f -x VendorID -t WS_X11 -t Qt_5_9_2 -x Py_v3 -B Qt_6_0_0 -P -c /home/jeff/Downloads/PyQt5_gpl-5.9/Qt -I sip -I /home/jeff/Downloads/PyQt5_gpl-5.9/sip sip/Qt/Qtmod.sip

Generating the .pro file for the Qt module...
Generating the pylupdate5 wrapper...
Generating the pyrcc5 wrapper...
Generating the pyuic5 wrapper...
Generating the Qt Designer plugin .pro file...
Generating the qmlscene plugin .pro file...
Re-writing
/home/jeff/Downloads/PyQt5_gpl-5.9/examples/quick/tutorials/extending/chapter6-plugins/Charts/qmldir...

Generating the .pro file for the dbus module...
Generating the top-level .pro file...
Making the pylupdate5 wrapper executable...
Making the pyrcc5 wrapper executable...
Making the pyuic5 wrapper executable...
Generating the Makefiles...
/home/jeff/Qt/5.9.2/gcc_64/bin/qmake -recursive PyQt5.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtCore/QtCore.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtGui/QtGui.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtHelp/QtHelp.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtMultimedia/QtMultimedia.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtMultimediaWidgets/QtMultimediaWidgets.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtNetwork/QtNetwork.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtOpenGL/QtOpenGL.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtPrintSupport/QtPrintSupport.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtQml/QtQml.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtQuick/QtQuick.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtSql/QtSql.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtSvg/QtSvg.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtTest/QtTest.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtWidgets/QtWidgets.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtXml/QtXml.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtXmlPatterns/QtXmlPatterns.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtDesigner/QtDesigner.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtDBus/QtDBus.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/_QOpenGLFunctions_2_0/_QOpenGLFunctions_2_0.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/_QOpenGLFunctions_2_1/_QOpenGLFunctions_2_1.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/_QOpenGLFunctions_4_1_Core/_QOpenGLFunctions_4_1_Core.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtSensors/QtSensors.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtSerialPort/QtSerialPort.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtX11Extras/QtX11Extras.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtBluetooth/QtBluetooth.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtPositioning/QtPositioning.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtQuickWidgets/QtQuickWidgets.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtWebSockets/QtWebSockets.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtWebChannel/QtWebChannel.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtWebEngineWidgets/QtWebEngineWidgets.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtLocation/QtLocation.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtNfc/QtNfc.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtWebEngineCore/QtWebEngineCore.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/QtWebEngine/QtWebEngine.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/pylupdate/pylupdate.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/pyrcc/pyrcc.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/Qt/Qt.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/designer/designer.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/qmlscene/qmlscene.pro
Reading /home/jeff/Downloads/PyQt5_gpl-5.9/dbus/dbus.pro

PyQt应忽略它无法识别所有Qt 5.x版本兼容性的Qt模块,因此“未知模块”位不太关注。

我正在使用:

  • Ubuntu 16.04
  • Python 2.7.12
  • Qt 5.9.2
  • SIP 4.19.3(源自编译)
  • PyQt 5.9(源自编译)

2 个答案:

答案 0 :(得分:1)

机器上存在旧版本的SIP,而不是从源代码构建的新版本,用于构建PyQt。删除旧版本的SIP可以解决问题。

$ python
>>> import sip
>>> print sip.SIP_VERSION_STR
4.17

使用sudo apt remove python-sip

删除旧版本后
$ python
>>> import sip
>>> print sip.SIP_VERSION_STR
4.19.3
>>> from PyQt5 import Qt    # Does not segfault

答案 1 :(得分:0)

我在其他设置(Slackware)上遇到了相同的问题,这导致Openshot在启动时无提示崩溃。

原因是,升级安装了来自不同来源(slackonly和Alienbob)的软件包。

通过搜索名为“ qt5”和“ Qt5”的软件包,我可以识别错误的软件包并将其替换为相关版本,从而解决了问题。