When I try to import Qt4 modules from within a virtual environment, I get the following error:
$ python -c 'from PyQt4 import QtCore, QtGui'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named PyQt4
The packages python-qt4, python-qt4-dev, and pyqt4-dev-tools are all installed on the system, and when I run the same command from outside of the virtual environment, I don’t get any errors. Any ideas how to fix this? I’m using Ubuntu 10.04, python 2.6, and virtualenv 1.8.2
The whole point of a virtualenv is that it is isolated from the rest of the system. Contemporary versions of virtualenv default to a configuration that excludes system Python packages. If you want to check whether your virtualenv was created with no site packages, follow the recommendations of the accepted answer in this question.
You need to install PyQt4 in the virtualenv. That process can trip up a first timer – so read through the answers to this question first.