Building PyQT5 with Python 2.7 on Ubuntu 16.04

So you want Qt5, but you have a lot of strict dependencies holding you back from going to Python 3. What to do? Go build everything yourself!

The following are steps based on a fresh install of Ubuntu 16.04, so adapt it per your needs.

First install the latest version of Qt. I was using the free open source edition. At the time of this post, the following was the set of commands given by Qt’s official website. I just downloaded the installation into my Downloads folder and ran it:

First download the installer:

Next, adjust the permissions and install Qt:

Now, that should have installed Qt5.x on your Ubuntu installation, it is time to install PyQt5 such that it uses Qt5 with Python 2.7. The key in this setup procedure is to build PyQt5 yourself.

First, SIP must be installed before proceeding with building PyQt5. You can download SIP from here. You can also just wget it!

Now is where things get important, as I always prefer to use virtual environments when working with Python, rather than installing everything on the global Python installation. After extracting the file, make sure to run configure.py using your virtual environment’s Python!

If the configuration was successful, the output should tell you that things related to SIP will be installed in your virtual environment’s folder, and NOT in your global Python that resides in /usr.

Now, running make and sudo make install will install SIP into your virtual environment folder, even if you are using sudo.

Now it is time to download PyQt5 and build it!

Configuration of PyQt5 is needed for building it. Again, using the right interpreter and the right parameters are key.

Now, assuming there are no errors, you should be able to run ‘import PyQt5’ in your virtual environment running Python 2.7!

13 thoughts on “Building PyQT5 with Python 2.7 on Ubuntu 16.04

  1. Good afternoon,

    I get an error when I run the next comand: “~/path/to/virtualenv/python configure.py”

    I have changed the path and write my virtualenv: “~/prefix/lib/python2.7” but it gives an error: “~/prefix/lib/python2.7 is a directory”

    How can I fix it?

    Thank you for the attention,

    Unai

    1. With your virtualenv activated, can you tell me what your console says when you type:
      which python

      Thanks!

  2. (python2.7ws) qwe:~/python2.7ws/bin/python2.7 configure.py -d ~/python2.7ws/lib/python2.7/site-packages/ –sip=~/python2.7ws/bin/sip –sip-incdir=../sip-4.19.3/siplib/ –qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake

    than i got the output: Usage: python configure.py [opts] [macro=value] [macro+=value]

    configure.py: error: ambiguous option: –sip (–sip-module, –sipdir?)

  3. i have this error
    ricci@ricci-Latitude-E6510:~/Descargas/PyQt5_gpl-5.9.2$ python configure.py -d cd /usr/local/lib/python2.7/site-packages/ –sip=/usr/local/bin –sip-incdir=../sip-4.19.3/siplib/ –qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake
    Usage: python configure.py [opts] [name=value] [name+=value]

    configure.py: error: ‘../sip-4.19.3/siplib/’ is not a directory

    1. @ricardo, Can you confirm that relative to the location that you are running that command, the folder ‘sip-4.19.3’ exists?

  4. hi!
    when I run the follw comand

    [~/Desktop/rdpy-test/python2-PyQt5/bin/python configure.py -d ~/Desktop/rdpy-test/python2-PyQt5/lib/python2.7/site-packages/ –sip=~/Desktop/rdpy-test/python2-PyQt5/bin/sip –sip-incdir=../sip-4.19.14/siplib/ -qmake= ~/Qt/5.9.2/gcc_64/bin/qmake]

    i get an next error: [configure.py: error: ‘~/Desktop/rdpy-test/python2-PyQt5/bin/sip’ is not an executable]

    how can I fix it?

    1. I had the same error and the sip package was already installed within the bin folder of my venv. I ran the configure.py by omitting the –sip option and it worked.

  5. Hello, Minsung.

    Im running the command :

    /home/tozadore/.virtualenvs/R-CASTLE/bin/python configure.py -d /home/tozadore/.virtualenvs/R-CASTLE/lib/python2.7/site-packages/ –sip=/home/tozadore/.virtualenvs/R-CASTLE/bin/sip –sip-incdir=../sip-4.19.3/siplib/ –qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake/
    This is SIP 4.19.6 for Python 2.7.12 on linux2.
    Usage: python configure.py [opts] [macro=value] [macro+=value]

    And getting the error:
    configure.py: error: ambiguous option: –sip (–sip-module, –sipdir?)

    PS: I checked the single dash as KX and that isent the problem.
    Thanks

  6. Hi Min Sung,

    I run the following command (omitting the –sip option):

    ~/virtualY/Stage/bin$ python configure.py -d ~/virtualY/Stage/lib/python2.7/site-packages/ –qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake

    and i get this error :

    Traceback (most recent call last):
    File “configure.py”, line 923, in
    main(sys.argv)
    File “configure.py”, line 764, in main
    for s in os.listdir(os.path.join(src_dir, “specs”)):
    OSError: [Errno 2] No such file or directory: ‘/home/isir2/virtualY/Stage/bin/specs’

    I’m not sure of which “configure.py” file i’m supposed to use.
    I think that i did not understand that part in your tutorial :

    ~/path/to/virtualenv/python configure.py

    Here i just copy+past the configure.py file that was on the sip directory to the bin directory. Pretty sure it’s the problem (i don’t have that configure.py file other way)

    Thank you for your time

Leave a Reply to Yann Mog Cancel reply

Your email address will not be published. Required fields are marked *