Wednesday, December 15, 2010

Compile and install PyQt4 for python2.7 in Ubuntu.

UPDATE:
The original post is from 2010 and since then the world has moved on. At the time of writing this update python27 is a default python version for Ubuntu. This means that to get PyQt and python27 running you no longer have to build PyQt from source. You can just install PyQt using apt-get:

sudo apt-get install python-sip python-qt4

I am keeping the original post in case you do need to build it from source (for example if you are using virtualenv, python3 or you are actually not using Ubuntu but a distribution that does not have a prepackaged PyQt).

ORIGINAL POST:

This tutorial shows how to build and install PyQt4 with python2.7 in Ubuntu.

If you want to use it with different version of python than 2.7 than replace every 2.7 in instructions below with the version you are using and it should work (tested with 2.6 and 3).

First, you need some prerequities:
sudo apt-get install python-pip python2.7-dev libxext-dev python-qt4 qt4-dev-tools build-essential

Then, try to install the PyQt and SIP using pip (it fails but it downloads the required packages to your ~/build/ folder).
pip install PyQt
pip install SIP

After that go to ~/build/SIP and install it
cd ~/build/SIP
python2.7 configure.py
make
sudo make install


Finally go to ~/build/PyQt and install it
Note: as PyQt is a big project - building it may take some time..
cd ~/build/PyQt
python2.7 configure.py
make
sudo make install


And that's all. You can test it by trying to import QtCore in python2.7
python2.7
>>> from PyQt4 import QtCore, QtGui


If there is no import error - you have PyQt4 installed correctly!

4 comments:

  1. Thanks! I love u! C:

    ReplyDelete
  2. DEAR NOODLY LORD THANK YOU.

    ReplyDelete
  3. how to install PyQt4 in centos 6.5 am using virtualenv
    am able to install wekit2png

    >>> import webkit2png
    Traceback (most recent call last):
    File "", line 1, in
    File "/usr/local/share/virtualenvs/test/lib/python2.7/site-packages/webkit2png-0.8.2-py2.7.egg/webkit2png/__init__.py", line 1, in
    from webkit2png import WebkitRenderer
    File "/usr/local/share/virtualenvs/test/lib/python2.7/site-packages/webkit2png-0.8.2-py2.7.egg/webkit2png/webkit2png.py", line 28, in
    from PyQt4.QtCore import *
    ImportError: No module named PyQt4.QtCore
    >>>



    can any one help

    ReplyDelete