RuntimeError: the sip module implements API v8.0 to v8.1 but the PyQt4.QtCore module requires API v7.1

情到浓时终转凉″ 提交于 2019-12-08 02:32:37

问题


I manually installed PyQt-4.9.1 and sip-4.13.2 under /tmp/yifli because the ones currently installed on the machine (running Fedora 13) are too old for my software.

After that, I added their locations to $PYTHONPATH and here is the output of sys.path:

>>> import sys
>>> print sys.path
['', '/tmp/yifli/lib/python/site-packages', '/tmp/yifli/lib/python/site-packages/PyQt4',    '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/Numeric', '/usr/lib/python2.6/site-packages/PIL', '/usr/lib/python2.6/site-packages/gst-0.10', '/usr/lib/python2.6/site-packages/gtk-2.0', '/usr/lib/python2.6/site-packages/scim-0.1', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info', '/usr/lib/python2.6/site-packages/webkit-1.0']

However, the error I got is due to the fact that somehow the old PyQt4 is still being used:

>>> import sip
>>> sip.__file__
'/tmp/yifli/lib/python/site-packages/sip.so'
>>> import PyQt4
>>> PyQt4.__file__
'/usr/lib/python2.6/site-packages/PyQt4/__init__.pyc'

How come?

P.S., I did get errors when I compiled Qt which complained some header file for Qt Phonon module cannot be found. But since I don't use that module, I just ignored it.

Yifei


回答1:


Firstly, installing things in /tmp is not a good idea, because it is intended only for temporary files (most systems will be set up to remove everything in /tmp during the boot or shutdown process).

Secondly, you should NEVER attempt to modify your system python or any of its packages - this will almost certainly lead to breakage of other applications that depend on python. If you need a different version of python and/or its packages, create a completely separate installation under /usr/local.

With that in place, you just need to ensure that your new python is specified whenever you are compiling packages for it.

So, to compile Sip you would do:

/usr/local/bin/python sip_source/configure.py

And for PyQt4, you would do the same - but also add a couple of other options that should avoid over-writing system files:

/usr/local/bin/python pyqt4_source/configure.py \
--qsci-api-destdir /usr/local/lib/qt4/qsci --no-designer-plugin

Once this has been set up, you can then create a simple wrapper script for running applications that need the upgraded python:

#!/bin/sh
exec /usr/local/bin/python myapp.py "$@"

Note that you do not need to change $PYTHONPATH for any of this to work, and so you should undo any changes you have made to it. (And you might also want to consider re-installing your fedora sip and pyqt packages to ensure everything is put back the way it was).

As for the errors regarding Phonon, the solution is simple: if the header files are missing, install the fedora package that contains them.



来源:https://stackoverflow.com/questions/9333915/runtimeerror-the-sip-module-implements-api-v8-0-to-v8-1-but-the-pyqt4-qtcore-mo

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