2

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

  • Also... I should say that I don't have any trouble importing any of the other PyQt modules (like PyQt4.QtCore or PyQt4.QtGui). – Dave Masselink Feb 24 '11 at 23:12
  • Can you show your .ui file? You may be using some component which derives from something in `QtDeclarative`. (I don't get `QtDeclarative` pulled in when I generate a .py from a .ui using `pyuic4`.) – Vinay Sajip Feb 25 '11 at 01:40
  • @Vinay: You asked the right question. I've been asking the wrong one all along! Why IS pyuic4 trying to include QtDeclarative. It must be due to something I am using in my .ui file. YOU'RE RIGHT! I looked through the .ui again and see that my Windows using colleague included a widget element that is called a QDeclarativeView. My version of QtDesigner doesn't even have this type of widget. Anyway, after taking this out, pyuic4 doesn't include the import... and I'm finally able to run my code without any problems! Thanks for asking the right question. – Dave Masselink Feb 25 '11 at 19:51

2 Answers2

0

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.

ajukraine
  • 561
  • 9
  • 27
0

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.

nmichaels
  • 49,466
  • 12
  • 107
  • 135
  • A QtDeclarative directory does exist... but I don't think it is from the PyQt install... I think it's just from Qt. It's at /usr/include/qt4/QtDeclarative – Dave Masselink Feb 24 '11 at 23:06
  • @Dave: Does it have an `__init__.py` file in it? – nmichaels Feb 24 '11 at 23:06
  • @nmichaels: No, it doesn't. Does one have to do anything special to install the QtDeclarative module of the PyQt4 package? – Dave Masselink Feb 24 '11 at 23:14
  • @Dave: I don't have an ubuntu box handy, but my Debian box's apt cache doesn't have the word `QtDeclarative` in it at all. Its PyQt4 package doesn't seem to include it. You may have to download it from [maemo](http://maemo.org/packages/view/python-pyside.qtdeclarative/). – nmichaels Feb 24 '11 at 23:19
  • @nmichaels: I might try that... OR... is there anyway you know of to configure pyuic4 to generate .py code that doesn't use the (relatively new) feature of QtDeclarative? – Dave Masselink Feb 24 '11 at 23:23
  • @Dave: Couldn't say. That might make a good separate question though. – nmichaels Feb 24 '11 at 23:29