There may be some similar questions like this one, but I didn\'t find any answer for me.
I tried some ways to do it like:
sudo aptitude install python-qt4-
On aws ubuntu (12.04 and 14.04):
sudo apt-get update
sudo apt-get install python-qt4
sudo apt-get install libxml2-dev libxslt1-dev python-dev
sudo apt-get install python-lxml
sudo apt-get install xvfb
Check this link and generate your-own-example.py
DISPLAY=localhost:1.0 xvfb-run python your-own-example.py
Voila.
You did in fact properly install the python bindings for Qt4 when you used:
sudo aptitude install python-qt4
You should usually use the Distribution-provided packages - the Ubuntu-provided packages are perfectly adequate for your needs.
What's puzzling me is the error you got after installing the Ubuntu package. I just tried this on a Ubuntu 12.04 installation and it worked for me. That suggests to me that your current installation of Ubuntu on your system is broken in some way.
You could try completely purging the python-qt4 package and reinstalling it again;
sudo apt-get remove --purge python-qt4
If you also issue:
sudo apt-get clean
... that will remove any downloaded package files from the system, so that apt will then download the package file again when you issue a
sudo apt-get install python-qt4
If that still doesn't work, then something very odd indeed is going on with your Ubuntu installation, and it might be wise to completely reinstall Ubuntu.