PyQt - QtDeclarative 导入问题

发布于 2024-10-18 21:25:32 字数 1174 浏览 6 评论 0 原文

我运行的是 Ubuntu 10.10,并通过 apt-get 安装了 PyQt 4.7.4。

我使用 QtDesigner 构建 GUI 布局,并使用 pyuic4 将 .ui 文件编译为 .py。

然后我对自动生成的类进行子类化并实现子类的构造函数。我调用 setupUi() ,然后收到以下错误和堆栈跟踪:

$ python src/gui/main_window.py 
Traceback (most recent call last):
  File "src/gui/main_window.py", line 2, in <module>
    from ui_main_window import Ui_MainWindow
  File "/home/dmass/sandbox/test/src/gui/ui_main_window.py", line 694, in <module>
    from QtDeclarative.QDeclarativeView import QDeclarativeView
ImportError: No module named QtDeclarative.QDeclarativeView

此外,当同事使用 Windows 中的 PyQt 4.8.3 安装中的 pyuic4 将 .ui 文件编译为 .py 时,我收到以下错误:

$ python src/gui/main_window.py  
Traceback (most recent call last):  
  File "src/gui/main_window.py", line 2, in <module>  
    from ui_main_window import Ui_MainWindow  
  File "/home/dmass/sandbox/test/src/gui/ui_main_window.py", line 705, in <module>  
    from PyQt4 import QtDeclarative  
ImportError: cannot import name QtDeclarative

看来 QtDeclarative当我安装 PyQt 时,没有安装(或者没有安装 Python 期望的位置)。但奇怪的是,我在谷歌搜索中找不到其他人有同样的问题。

有谁知道这是怎么回事?感谢您的帮助!

戴夫

I am running Ubuntu 10.10, and I installed PyQt 4.7.4 through apt-get.

I build a GUI layout with QtDesigner and compile the .ui file to .py using pyuic4.

Then I subclass the auto-generated class and implement the subclass's constructor. I call setupUi() and then receive the following error and stack trace:

$ python src/gui/main_window.py 
Traceback (most recent call last):
  File "src/gui/main_window.py", line 2, in <module>
    from ui_main_window import Ui_MainWindow
  File "/home/dmass/sandbox/test/src/gui/ui_main_window.py", line 694, in <module>
    from QtDeclarative.QDeclarativeView import QDeclarativeView
ImportError: No module named QtDeclarative.QDeclarativeView

Additionally, when a colleague compiles the .ui file to .py using pyuic4 from a PyQt 4.8.3 install in Windows, I receive the following error:

$ python src/gui/main_window.py  
Traceback (most recent call last):  
  File "src/gui/main_window.py", line 2, in <module>  
    from ui_main_window import Ui_MainWindow  
  File "/home/dmass/sandbox/test/src/gui/ui_main_window.py", line 705, in <module>  
    from PyQt4 import QtDeclarative  
ImportError: cannot import name QtDeclarative

It appears that QtDeclarative wasn't installed (or not where Python expects) when I installed PyQt. But oddly, I couldn't find anyone else with the same problem in my google searching.

Does anyone know what's going on here? Thanks for your help!

Dave

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

豆芽 2024-10-25 21:25:32

你的 ubuntu 系统上应该有一个名为 QtDeclarative 的目录。确保它位于您的 PYTHONPATH 中。对于 PyQt4,应该在 Windows 计算机上执行类似的操作。

There should be a directory somewhere on your ubuntu system called QtDeclarative. Make sure it's in your PYTHONPATH. Something similar should be done on the Windows machine for PyQt4.

谜兔 2024-10-25 21:25:32

在 Ubuntu 10.10 (Maverick) 包 python-qt4 下,包的 文件列表。但是 Ubuntu 11.04 (Natty) 中出现了 QtDeclarative.so

因此,在这种情况下,您可以将整个操作系统更新为 Natty,或者尝试手动将此文件复制并粘贴到您的 python 路径中。

更新。刚刚尝试在我的 Debian Squeeze 中执行此操作,但由于依赖 libqt4-declarative 而失败。然而,对于 Ubuntu Maverick 来说,已经有了 maverick/libqt4-declarative

PS。但您应该知道 - 手动复制不是首选方式。

At Ubuntu 10.10 (Maverick) under package python-qt4 there is no QtDeclarative binding in the package's filelist. But QtDeclarative.so presents in Ubuntu 11.04 (Natty).

So in that case you could update whole your OS to Natty or try to manually copy and paste this file into your python path.

UPDATE. Just tried to do it in my Debian Squeeze, but failed because of dependency libqt4-declarative. However for Ubuntu Maverick there is already maverick/libqt4-declarative.

PS. But you should know - manual copying is not preferred way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文