Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 导入时pyqt5分段错误_Python_Qt_Pyqt_Segmentation Fault_Pyqt5 - Fatal编程技术网

Python 导入时pyqt5分段错误

Python 导入时pyqt5分段错误,python,qt,pyqt,segmentation-fault,pyqt5,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 du

从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配置脚本中的代码。下面是一个缩写版本

$ 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应该忽略在所有Qt5.x版本中都无法识别的Qt模块,因此“未知模块”位不太重要

我正在使用:

  • Ubuntu 16.04
  • Python 2.7.12
  • Qt 5.9.2
  • SIP 4.19.3(根据源代码编译)
  • PyQt 5.9(从源代码编译)

机器上存在旧版本的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

我在不同的设置(Slackware)中遇到了同样的问题,这导致Openshot在启动时无声地崩溃

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


通过搜索名为“qt5”和“qt5”的包,我可以识别出错误的包,并用相关版本替换它们,从而解决了问题。

尝试:
从PyQt5.QtCore导入Qt
它给出了相同的结果。使用python 2.7.14、Qt 5.9.1、sip 4.19.3和pyqt 5.9,它对我来说效果很好。gdb输出没有实际用途,除非您在启用调试sysmbols的情况下编译所有内容。我怀疑某处缺少依赖关系。当您从PyQt5导入Qt时,它会尝试按字面意思导入,包括像webengine和webkit这样的重量级模块。为什么要从源代码编译?为什么不直接使用ubuntu提供的软件包呢?我使用Python2.7.14、Qt5.9.2、SIP4.19.3和PyQt5都可以使用它。9@ekhumoroUbuntu repos提供了PyQt5.5.1和Qt5.5.1版本。我与另一个程序存在兼容性问题,需要升级到5.9。你知道我会错过什么吗?PyQt仅将SIP列为依赖项。即使使用4.19.3,这仍然会对我造成故障。您是否安装了PyQt 4?它需要使用与PyQt 5安装相同的SIP版本进行编译。