I am trying to build PyQt 4 because it is used by the program that I need to run.
While it is trivial to install PyQt 5 with a single command pip install PyQt5
, the same is not possible with the older PyQt 4 and people recommend building it from source.
I have installed SIP like suggested on the PyQt4 Download.
I have also downloaded PyQt 4 and untarr'ed it. Now when I am running the python configure.py --verbose
, I get
Stanislaw@home:PyQt4_gpl_mac-4.12.3 (master)*$ python configure.py --verbose
Determining the layout of your Qt installation...
/usr/local/bin/qmake -spec macx-g++ -o qtdirs.mk qtdirs.pro
make -f qtdirs.mk
g++ -c -pipe -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/local/etc/qt4/mkspecs/macx-g++ -I. -I/usr/local/Cellar/qt@4/4.8.7_6/lib/QtCore.framework/Versions/4/Headers -I/usr/local/Cellar/qt@4/4.8.7_6/lib/QtCore.framework/Versions/4/Headers -I/usr/local/include -I. -F/usr/local/lib -o qtdirs.o qtdirs.cpp
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
...
/usr/local/lib/QtCore.framework/Headers/qglobal.h:68:10: fatal error: 'algorithm' file not found
#include <algorithm>
^~~~~~~~~~~
I don't have any experience with Qt/qmake but I would guess that this older version of PyQt doesn't configure itself to use the Clang-based C++ toolchain of macOS correctly.
I will continue digging but I would also like to know if a trivial solution existed for this problem.
This is probably not the best/right way of building PyQt 4 but I got it built and now my program is running.
The solution below requires Qt to be installed. I installed it with
brew install cartr/qt4/pyqt@4
Now the PyQt part.
PyQt installation consists of 3 steps:
python configure.py
make
make install
To make the python configure.py
step work
I had to change this in the configure.py
file:
-qt_macx_spec = 'macx-g++'
+qt_macx_spec = 'macx-llvm'
At the second step, when running make
I got the same error as before but this time it came from the generated Makefiles. It turned out that increasing the version in the -mmacosx-version-min=10.5
flag to -mmacosx-version-min=10.10
(by replacing this line in all of the generated Makefiles) made the error go away.
(My interpretation of this would be that the later versions of macOS SDKs do not use the old C++ standard library of GCC but the C++ library of their newer Clang C++ toolchain.)
After that, when running my PyQt4-based application I hit:
ImportError: No module named sip
The solution was found here: I had to rebuilt SIP with additional flag:
cd sip-4.19.22
# `make clean` is important otherwise rebuilding will not work
# your program might complain with
# "ValueError: PyCapsule_GetPointer called with incorrect name"
make clean
python configure.py --sip-module PyQt4.sip