RuntimeError: sip 模块实现了 API v8.0 到 v8.1 但 PyQt4.QtCore 模块需要 API v7.1 [英] RuntimeError: the sip module implements API v8.0 to v8.1 but the PyQt4.QtCore module requires API v7.1

查看:49
本文介绍了RuntimeError: sip 模块实现了 API v8.0 到 v8.1 但 PyQt4.QtCore 模块需要 API v7.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 /tmp/yifli 下手动安装了 PyQt-4.9.1 和 sip-4.13.2,因为机器上当前安装的(运行 Fedora 13)对于我的软件来说太旧了.

之后,我将它们的位置添加到 $PYTHONPATH 中,这是 sys.path 的输出:

<预><代码>>>>导入系统>>>打印 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-旧的','/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']

然而,我得到的错误是由于旧的 PyQt4 仍在使用中:

<预><代码>>>>进口 sip>>>sip.__文件__'/tmp/yifli/lib/python/site-packages/sip.so'>>>导入 PyQt4>>>PyQt4.__file__'/usr/lib/python2.6/site-packages/PyQt4/__init__.pyc'

怎么会?

P.S.,我在编译 Qt 时确实遇到错误,它抱怨找不到 Qt Phonon 模块的某些头文件.但是因为我不使用那个模块,所以我忽略了它.

逸飞

解决方案

首先,在 /tmp 中安装东西不是一个好主意,因为它仅用于临时 文件(大多数系统将设置为在启动或关闭过程中删除 /tmp 中的所有内容).

其次,您应该永远尝试修改您的系统 python 或其任何包 - 这几乎肯定会导致依赖 python 的其他应用程序损坏.如果您需要不同版本的 python 和/或其包,请在 /usr/local 下创建一个完全独立的安装.

有了它,您只需要确保在为它编译包时指定新的 python.

因此,要编译 Sip,您将执行以下操作:

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

对于 PyQt4,您可以这样做 - 但还要添加一些其他选项,以避免覆盖系统文件:

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

设置完成后,您可以创建一个简单的包装脚本来运行需要升级的 Python 的应用程序:

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

请注意,您无需更改 $PYTHONPATH 即可使其中任何一项工作,因此您应该撤消对它所做的任何更改.(而且您可能还想考虑重新安装您的 Fedora sip 和 pyqt 包,以确保一切都恢复原状.

对于 Phonon 的错误,解决方法很简单:如果头文件丢失,请安装包含它们的 fedora 包.

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

解决方案

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.

这篇关于RuntimeError: sip 模块实现了 API v8.0 到 v8.1 但 PyQt4.QtCore 模块需要 API v7.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆