简体   繁体   中英

Qt4 issue in python virtual environment

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM