PyQt4 on centos 6 with alma's python 2.7

The situatuation:

Short summary:

There is a PyQt4 package for centos6.

It does not work because it is only for python2.6 that comes with centos6 too.

Our python is python2.7 which is installed in /alma/ACS-2017DEC/ACSSW/lib/Python

I tried to build PyQt4 from source with these instructions: <a data-saferedirecturl="https://www.google.com/url?q=http://pyqt.sourceforge.net/Docs/PyQt4/installation.html&source=gmail&ust=1549982033590000&usg=AFQjCNGk7azAneJQqp9aJJA6ln_qApnTHA" href="http://pyqt.sourceforge.net/Docs/PyQt4/installation.html" target="_blank">http://pyqt.sourceforge.net/Docs/PyQt4/installation.html</a>

However, that is also impossible because it requires qt4. Qt4 is installed by the centos6 but only a statically linked version so it is only possible to create a statically linked version of PyQt4. Such a version can be used to recompile python with PyQt4 statically linked into it but that is not what we want. Unfortunately, python cannot read the statically linked PyQt4 packages at all at runtime and PyQt4 makefile forbids the creation of dynamically linked PyQt4 from a statically linked qt4 installation.

There are two possible solutions: 1) recompile qt4 from source (in that case: better upgrade to qt5 while you're at it). 2) go the static way and rebuild python after installing pyqt (this probably requires some extra flags during compilation on top of the ACS build instructions).

The above two solutions are cumbersome and require recompiling large software suites, potentially breaking others things. I found two easier solutions:

Easy solution 1:

I found this very hacky workaround:

cp -r /usr/lib64/python2.6/site-packages/PyQt4 /alma/ACS-2017DEC/ACSSW/lib/python/site-packages
cp /usr/lib64/python2.6/site-packages/sip.so /alma/ACS-2017DEC/ACSSW/lib/python/site-packages

Rather to my surprise that seems to work. (it simply copies some of the files installed by the yum package to the alma python searchpath).

What I don't understand is how the centos maintainers managed to build the .so (dynamically loaded) PyQt4 modules in that directory if the qt4 that ships with centos is truely statically loaded and the PyQt4 build script appears to forbid that combination.

I'm still waiting for that to fail. My feeling is that there must be things that break between python 2.6 and 2.7... I created a quick test with a window and a button and that appears to work but I'm very afraid that this is going to cause trouble later on.

Slightly more advanced solution 2:

make and install sip (it's a dependency of PyQt):

wget https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.13/sip-4.19.13.tar.gz
tar -zxvf sip-4.19.13.tar.gz
cd sip-4.19.13/
python configure.py --sip-module PyQt4.sip --no-dist-info --no-tools -d /alma/ACS-2017DEC/ACSSW/lib/python/site-packages
make
make install
cd ..

Get PyQt4:

wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.12.3/PyQt4_gpl_x11-4.12.3.tar.gz
tar -zxvf [[PyQt4][PyQt4]]_gpl_x11-4.12.3.tar.gz
cd [[PyQt4][PyQt4]]_gpl_x11-4.12.3/

The following patch is needed because configure-ng.py wrongly detects that qt is statically linked which it is not: (this path also occurs in the distro build of the PyQt package if you look in here: http://vault.centos.org/6.10/os/Source/SPackages/)

cat <<EOF | patch --ignore-whitespace configure-ng.py
691c691
<         self.qt_shared = (lines[1] == 'shared')
---
>         self.qt_shared = True

EOF

Prepare the build:

python configure-ng.py --qmake /usr/bin/qmake-qt4 --destdir /alma/ACS-2017DEC/ACSSW/lib/python/site-packages --confirm-license

Another patch is needed because of a version incompatibility between the qt version and pyqt version that we use:

cat <<EOF | patch --ignore-whitespace QtGui/sipQtGuiQAbstractPrintDialog.cpp
1782d1781
<         {sipName_PrintCurrentPage, static_cast<int>( ::QAbstractPrintDialog::PrintCurrentPage), 17},
EOF

Ready to make and install (no sudo needed because we install in /alma):

make
make install
What to expect:

If everything went ok then the following program should show a window with a button: (copy into ipython or python shell, don't forget you'll need X forwarding if you're logged in via ssh):

import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
btn = QtGui.QPushButton('Hello World', w)
btn.resize(btn.sizeHint())
btn.move(50, 50)
def callback():
 print("Hello World!!!")
btn.clicked.connect(callback)
w.show()

-- Sjoerd Timmer - 2019-02-11

Comments


Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2019-02-11 - SjoerdTimmer
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback