0

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

tdc
  • 8,219
  • 11
  • 41
  • 63

2 Answers2

3

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.

Community
  • 1
  • 1
Ngure Nyaga
  • 2,989
  • 1
  • 20
  • 30
0

Starting with virtualenv 1.7 --no-site-packages became the default behavior. To make global site packages importable (which used to be the default) you must use the option --system-site-packages when you create the virtualenv.

tdc
  • 8,219
  • 11
  • 41
  • 63