How to build PyQt5 on Ubuntu
Question: I'm trying to move my work from `PySide` to `PyQt5`.

My project works with `Python3.4.1` yet Ubuntu's default python3 is
`Python3.4.0`, So I have to compile `PyQt5` by myself.

`Python3.4.1`'s path is `/opt/python3.4.1/bin/python3.4` and it works well

my system is ubuntu14.04

* * *

First, I download the source from official site, `PyQt-gpl-5.3.1.tar.gz` and
`sip-4.16.2.tar.gz`. Sip was installed successfully while an error occurs with
making `pyqt`.

my command is:

    
    
    $/opt/python3.4.1/bin/python3.4 configure.py
    $make
    

and the erro is

> g++ -m64 -Wl,-O1 -shared -o libpyqt5qmlplugin.so pluginloader.o
> moc_pluginloader.o -L/usr/X11R6/lib64 -L/opt/python3.4.1/lib -lpython3.4m
> -lQt5Qml -L/usr/lib/x86_64-linux-gnu -lQt5Network -lQt5Gui -lQt5Core -lGL
> -lpthread
>
> /usr/bin/ld: /opt/python3.4.1/lib/libpython3.4m.a(abstract.o): relocation
> R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making
> a shared object; recompile with -fPIC
>
> /opt/python3.4.1/lib/libpython3.4m.a: error adding symbols: Bad value
>
> collect2: error: ld returned 1 exit status
>
> make[1](http://pyside.readthedocs.org/en/latest/building/linux.html): _*_
> [libpyqt5qmlplugin.so] Error 1

The error do not raise when I use the default `$python3 configure.py` and
looks quite similar to an error when I build PySide(it is fixed by
[this](http://pyside.readthedocs.org/en/latest/building/linux.html)). But I am
weak in compiling so I can't fix pyqt like they do with pyside.

I also tried `pip install PyQt5` in my `virtualenv`, unfortunately, got the
same failure like [this](http://stackoverflow.com/questions/21577723/can-not-
install-pyqt5-from-the-python-packaging-index).

Even the successful build (looks like) with default python, two error shows
when running.

  1. the default install path is "site-packages", which is instead of "dist-packages" on ubuntu. So I have to change my PYTHONPATH by myself.

  2. which is the most annoying problem, when I import it:

> from PyQt5 import QtCore, QtGui

an error occurs :

> Traceback (most recent call last): File "", line 1, in from PyQt5 import
> QtCore, QtGui RuntimeError: the sip module implements API v11.0 but the
> PyQt5.QtCore module requires API v11.1

All the source is the latest released on the official site ! Is that a joke?

* * *

Finally, I use `apt-get install python3-pyqt5` to install pyqt to my default
python3.4.0. It works well now, and I still can't find a way to build a PyQt
for python3.4.1.


Answer: It is really a hard work!

> /usr/bin/ld: /opt/python3.4.1/lib/libpython3.4m.a(abstract.o): relocation
> R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making
> a shared object; recompile with -fPIC

This error raise because the linker could not find `libpythonX.X.so`. When I
built my `Python3.4.1`, I used only one option`--prefix`, so I do not have a
shared lib in my python's lib.

Then I rebuild my python with `--enable-shared`, then install `PyQt5`, and
successfully import PyQt.

However, I realize my python version is 3.4.0! Python exec. was linked to
system python's lib...

This article helps me a lot: <http://koansys.com/tech/building-python-with-
enable-shared-in-non-standard-location>

Finally, I add `LDFLAGS= -Wl,-rpath /opt/python3.4.1/lib` to configure option:

> ./configure --prefix=/opt/python3.4.1 --enable-shared LDFLAGS= -Wl,-rpath
> /opt/python3.4.1/lib

and then installed PyQt5.

Now, I can enjoy it~(≧▽≦)/~

