ImportError: No module named sip (python2.7 PyQt4)

Gabriel G. picture Gabriel G. · Mar 29, 2019 · Viewed 7.8k times · Source

I'm currently using Ubuntu 18.04 LTS.

I'm trying to install a program that need PyQt4 and QtWebKit, so a manual installation is necessary as QtWebKit have been excluded from PyQt4.

I downloaded sip 4.19.12 (with 4.19.14 installation of PyQt4 fails) and PyQt4 4.12.13

I ran a virtualenv, made sure it was working as intended and tried installing sip, which works:

$ python configure.py
$ make
$ make install

Then I proceed with the same with PyQt4, with no errors.

When I try to run my program .py, it gives the following error:

$ python RNAEditor.py
Traceback (most recent call last):
File "RNAEditor.py", line 9, in <module>
from Helper import Helper, Parameters
File "/home/bioinfo/Documentos/Ferramentas_RNAEditor/RNAEDITOR_ch/Helper.py", line 13, in <module>
from PyQt4 import QtCore
ImportError: No module named sip

$ sudo python RNAEditor.py 
Traceback (most recent call last):
File "RNAEditor.py", line 9, in <module>
from Helper import Helper, Parameters
File "/home/bioinfo/Documentos/Ferramentas_RNAEditor/RNAEDITOR_ch/Helper.py", line 13, in <module>
from PyQt4 import QtCore
ImportError: No module named PyQt4

I'm sure that my virtual env does have sip and PyQt4, as importing both within virtualenv/python gives no error too.

$ python
>>> import PyQt4
>>> import sip
>>> from PyQt4 import QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sip

Any ideas on how to set PyQt4 and sip with a manual installation, or why it is not working as intended?

Answer

John Govage picture John Govage · Oct 21, 2019

PyQt started from version 4.12.2 needs private sip module called PyQt4.sip (see file NEWS in PyQt 4 source folder) So you should configure sip using this command: python configure.py --sip-module PyQt4.sip After sip is built, you should copy file sip.pyd to PyQt4 python directory - by default it is c:\python27\Lib\site-packages\PyQt4