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

那年仲夏 提交于 2020-05-29 11:06:59

问题


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?


回答1:


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




回答2:


I got it to work with specific SIP and PyQt4 versions and running inside a virtualenv. I have no idea what happens, but it seems that in Ubuntu 18.04 something happens with the last versions of PyQt4 and SIP and they do not work as intented, but they do work in Ubuntu 16.04 (tested). The code that worked in Ubuntu 18.04 is:

PYQT4 4.12.1 and sip 4.19.12

sudo apt-get install python-pip python2.7-dev libxext-dev python-qt4 qt4-dev-tools build-essential

pip install virtualenv


virtualenv PROJECTNAME
source PROJECTNAME/bin/activate


cd SIP_SOURCE_DIRECTORY
python configure.py
make
make install

cd PYQT4_SOURCE_DIRECTORY
python configure.py
make
make install

Then you have your virtualenv where QtWebKit is supported, which is important for many applications



来源:https://stackoverflow.com/questions/55424762/importerror-no-module-named-sip-python2-7-pyqt4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!