I’m running Python 2.6.6 on Ubuntu 10.10.
I understand that we can import a module and bind that module to a different name, e.g.
import spam as eggs
also,
from eggs import spam as foo
My problem is that when running the PySide examples, the following import code does not run:
import PySide as PyQt4
from PyQt4 import QtCore, QtGui
It generates an import error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
Clearly, according to the Python interpreter the above code is incorrect, my question is why is it incorrect or rather why doesn’t this work?
importandfromare a special syntax.They look for a module name, which means a file in
sys.pathwhich 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
PyQt4in your namespace after runningimport PySide as PyQt4does not change anything, Python is still looking for an actual module calledPyQt4when you dofrom PyQt4 import QtCore, QtGui.Try doing
or
That should be equivalent.