I’ve never been a fan of the Qt library (it might take a long post to explain the reasons, but I don’t have time to write). However, there are a few good programs I want to use which requires Qt library. Installing Qt library on Mac OS was not difficult, thanks to the effort by Nokia: you can download an installer for Mac OS on http://qt.nokia.com/downloads.
Difficulty arose when I installed PyQt4, the Qt wrapper for Python, which is used by quite a few Python programs such as Spyder, Eric4, Leo. After installing SIP successfully, I tried to build PyQt4 and got an error at the linking phase. It took me several hours to figure what went wrong and how to fix the problems. The problem is that the Qt library is 32bit while, by default, python builds PyQt4 in 64bit. That caused problem when it tried to link 64bit object files with 32bit Qt library. To fix this issue, we need to force python to build PyQt4 in 32bit, and we also need to re-build SIP in 32bit mode. In fact, there exists a document on the PyQt website that explains how to build PyQt4 on Mac OS/Snow Leopard, but it is not in the README file in the source distribution. I will summarize the steps below:
- If you use the python version that comes with Mac OS (2.5 for Snow Leopard), make sure that it runs in 32bit mode by issuing the command
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
in the terminal. Alternatively, set the following environment variable:
export VERSIONER_PYTHON_PREFER_32_BIT=yes - Re-build SIP in 32bit
- Configure SIP to build in 32bit by the command:
python configure.py --arch i386 - Build and install SIP:
make
sudo make install
- Configure SIP to build in 32bit by the command:
- Build PyQt4 in 32bit
- Configure PyQt4 to build in 32bit:
python configure.py --use-arch i386 - Build and install PyQt4:
make
sudo make install
- Configure PyQt4 to build in 32bit:
- If every step is successful, you should have PyQt4 built and installed. To test it, either run the provided examples or open a Python console and try:
import PyQt4. It should not give any error.
Now, all Python programs that use PyQt4 should run fine.
Pingback: Install QScintilla2 (to install Eric4) on Mac OS Snow Leopard | Truong's Weblog
This is what I get when I configure PyQT:
Generating the C++ source for the QtCore module…
sh: /Users/apy/tmp/env27/bin/../bin/sip: No such file or directory
Error: Unable to create the C++ code.
Any suggestions? Many thanks,
Fred
It seems that SIP could not be found on your system. Did you rebuild and install SIP (step 2) before configuring PyQT?
Thanks Truong, re-did it and it works!
Hi,
every time I run the :python configure.py –use-arch i386 for PyQt it gives me this error
Error: Make sure you have a working Qt v4 qmake on your PATH or use the -q
argument to explicitly specify a working Qt v4 qmake.
Any suggestions? Many thanks,
Illia Z.
Just as the error message suggested: have you installed Qt4 for Mac? can you run qmake in the console? if yes, is it the version coming with Qt4? if no, you must either put it on your PATH environment variable or use -q followed by the explicit path to qmake.
On MacOsX Lion, if I enter : python configure.py -q /Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake -d /Library/Python/2.7/site-packages/ –use-arch i386 –verbose it failed complaining :
Undefined symbols for architecture i386:
“QTextStream::QTextStream(QIODevice*)”, referenced from:
_main in qtdirs.o
“QTextStream::~QTextStream()”, referenced from:
_main in qtdirs.o
“QTextStream::operator<<(char const*)", referenced from:
_main in qtdirs.o
"QTextStream::operator<<(QString const&)", referenced from:
_main in qtdirs.o
"QTextStream::operator<<(char)", referenced from:
_main in qtdirs.o
"QTextStream::operator<<(int)", referenced from:
_main in qtdirs.o
"QLibraryInfo::licensee()", referenced from:
_main in qtdirs.o
"QLibraryInfo::location(QLibraryInfo::LibraryLocation)", referenced from:
_main in qtdirs.o
"QCoreApplication::QCoreApplication(int&, char**, int)", referenced from:
_main in qtdirs.o
"QCoreApplication::~QCoreApplication()", referenced from:
_main in qtdirs.o
"QFile::open(QFlags)”, referenced from:
_main in qtdirs.o
“QFile::QFile(QString const&)”, referenced from:
_main in qtdirs.o
“QFile::~QFile()”, referenced from:
_main in qtdirs.o
“QString::fromAscii_helper(char const*, int)”, referenced from:
QString::QString(char const*)in qtdirs.o
“QString::free(QString::Data*)”, referenced from:
QString::~QString()in qtdirs.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
lipo: can’t open input file: /var/tmp//ccGz7Yrt.out (No such file or directory)
make: *** [qtdirs.app/Contents/MacOS/qtdirs] Error 1
Error: Failed to determine the layout of your Qt installation.
An idea of what’s wrong !
I don’t know much about Lion. Probably Apple dropped support for 32-bit architecture altogether, therefore you cannot build 32-bit binary anymore.
This post is old. Probably QT now has 64-bit support and you don’t need to compile 32-bit.