【问题标题】:pyqt5 segmentation fault on importpyqt5 导入时出现分段错误
【发布时间】:2017-10-17 16:53:31
【问题描述】:

从 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(从源代码编译)

【问题讨论】:

  • 试试:from PyQt5.QtCore import Qt
  • 它给出了相同的结果。
  • 它适用于我使用 python 2.7.14、qt 5.9.1、sip 4.19.3 和 pyqt 5.9。 gdb 输出没有真正的用处,除非您在启用调试 sysmbols 的情况下编译所有内容。我怀疑某处缺少依赖项。当您执行from PyQt5 import Qt 时,它会尝试按字面意思导入everything,包括像webengine 和webkit 这样的重量级模块。你为什么要从源代码编译?为什么不直接使用ubuntu提供的包呢?
  • 它适用于我使用 python 2.7.14、qt 5.9.2、sip 4.19.3 和 pyqt 5.9
  • @ekhumoro Ubuntu 存储库提供版本 PyQt 5.5.1 和 Qt 5.5.1。我遇到了与单独程序的兼容性问题,需要升级到 5.9。知道我可能缺少哪些依赖项吗? PyQt 的 install doc 仅将 SIP 列为依赖项。

标签: python qt pyqt segmentation-fault pyqt5


【解决方案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

【讨论】:

  • 这对我来说仍然是段错误,即使是 4.19.3。
  • 你安装了 PyQt 4 吗?它需要使用与您的 PyQt 5 安装相同的 SIP 版本进行编译。
【解决方案2】:

我在不同的设置 (Slackware) 上遇到了同样的问题,这导致 Openshot 在启动时静默崩溃。

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

搜索以“qt5”和“Qt5”命名的包使我能够识别错误的包并将其替换为相关版本,从而解决了问题。

【讨论】:

    猜你喜欢
    • 2016-07-11
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 2018-12-19
    • 2016-03-29
    • 1970-01-01
    相关资源
    最近更新 更多