-1

I have installed PyQt4 through Macport sudo port install py27-pyqt4 and virtualenv with pip install virtualenv. Whenever I run my PyQt programs while i am in the virtual environment I would receive the following error:

ImportError: No module named PyQt4.QtGui

However, I am able to run the same application when I am out of the virtual environment. What could be the reason for this issue and how do I resolve it?

luishengjie
  • 187
  • 6
  • 15
  • Did you activate the virtualenv and install the library while having it activated? – Bahrom Apr 18 '16 at 18:13
  • no i did not. I have tried recreating the virtualenv environment after installing the library, but the error continues to propagate. – luishengjie Apr 18 '16 at 18:19

1 Answers1

0

Looks like you may have not installed PyQt4 into the virtual environment, usually the steps are as follows:

1) Create a virtual env: virtualenv ve_name

2) Activate the created virtualenv: source path_to_ve_name/bin/activate (at this point your shell will get ve_name prepended to it, and your $PATH will get updated, so whatever you install via pip will end up going into path_to_ve_name/bin)

3) Install all the dependencies while keeping ve_name active: pip install package-name, etc.

Once you have done this, you need to install PyQt4 into that virtual environment, there's an example here: How to install SIP and PyQt on a virtual environment? It looks like a simple pip install doesn't work with PyQT, so check out the suggestions in that question.

When you are done dealing with ve_name, you just need to deactivate your virtual environment (using command deactivate from your shell). This will revert your $PATH variable, and you can either create a new ve for a new project, or resume working on the same project by reactivating the created ve.

Community
  • 1
  • 1
Bahrom
  • 4,752
  • 32
  • 41