PyQt - QtDeclarative import troubles

2.3k views Asked by At

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

2

There are 2 answers

6
nmichaels On

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.

0
ajukraine On

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.