2 Answers
2

They look for a module name, which means a file in sys.path which starts with the module name.

And it seems like you don't have PyQt4 installed, so it will fail.

The fact that you have a variable called PyQt4 in your namespace after running import PySide as PyQt4 does not change anything, Python is still looking for an actual module called PyQt4 when you do from PyQt4 import QtCore, QtGui.

Thanks, you're right PyQt4 being the actual module. It didn't cross my mind although I should have known better. I was just wondering why the PySide developers decided to write their import statement that way. Anyways, thanks.
–
Mustafa KhattabFeb 24 '11 at 1:34

I just installed PySide and was doing a tutorial where all the examples used PyQt4. I got tired of changing the imports from PyQt4 to PySide so I just made a symlink in my site-packages, using the following steps:

1) There's surely a better way but I found where my python packages were installed by opening a shell and running python, then at the interactive interpreter typed:

>>> import sys
>>> print sys.path

2) I then found PySide in one of the directories and cd'd to it (n.b. It's at /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages if you're using the macports PySide install for python 2.7 on Mac OSX Leopard 10.5.8).

3) Then I made a symlink with ln, in my case I had to use sudo:

sudo ln -s PySide PyQt4

That's it, now I can just use:

from PyQt4 import QtGui

as normal - happy days!

Obviously, if you ever want to install PyQt4 you should rm the PyQt4 symlink first.
Another caveat: What I've described above may well be wrong/bad in many ways - I am no expert at Python installs but so far it's ok for me. YMMV so use at your own risk. Hopefully someone will comment soon to say "no, very bad!" or ideally "yeah don't sweat it, we cool.."