aldo aldo - 1 year ago 146
Python Question

Python 2.7 crashes when importing PyQt4.QtDeclarative or PyQt4.Qt on Ubuntu

Some time ago (months?) the program

started crashing on startup (SIGSEGV) on my machine. I finally tracked it down a little deeper and found that the problem occurs while python is trying to import
. Unfortunately I don't remember when this started happening, and my Internet searches have turned up nothing. Any ideas what's going wrong? I suspect an incompatible package update somewhere along the way, but have no idea how to find the root cause.

Here's a simple session transcript:

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4 import QtDeclarative
Segmentation fault (core dumped)

Here's some system information:

$ uname -a
Linux [HOSTNAME] 3.13.0-63-generic #103-Ubuntu SMP Fri Aug 14 21:42:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

$ which python
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Jan 8 2015 /usr/bin/python -> python2.7


I found later that I had the same problem (Segmentation fault) when doing
import PyQt4.Qt
as well.

Answer Source

It can be difficult to diagnose a segfault when the only error message is

Segmentation fault (core dumped)

In this case, because reinstallation of python-qt4 does not take much time at all, I would recommend you do it by running:

sudo apt-get install --reinstall python-qt4

Edit: It looks like OP encountered another segfault when doing import PyQt4.Qt. This is probably related to python-sip, which is a dependency of python-pyqt4. To get rid of the segfault, reinstall python-sip by running:

sudo apt-get install --reinstall python-sip
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download