The OpenCASCADE library is built upon X11. It doesn’t use Cocoa/Carbon. In order to be able to use the 3D viewer of pythonOCC with PyQt, you must first install Qt4-x11 and then PyQt4.7.
First, from the finkproject, download/install the qt4-x11 package. You can use finkcommander, a graphical frontend to fink, to manage your fink packages. Select the package named ‘qt4-X11′, install from source, and just be patient. When the build is achieved, your fink commander window should look like that:
The Qt4.5.2 libraries have been installed to /sw/lib/qt4-X11. Add the following line to your .bash_profile:
export PATH=$PATH:/sw/lib/qt4-x11/lib/:/sw/lib/qt4-x11/bin/
To check that your Qt installation is clean, just try to launch Qt Designer:
thomas-macbookpro:bin thomas$ designer
The next step is to install PyQt4. You will find below a link to a precopiled binary of PyQt4.7 that works with the previous installation.
PyQt4.7-MacOSX-SL-64.zip (11.5Mb)
Just extract the content of this file to /Library/Python/2.6/site-packages and you should get done. Test the installation (no linkage errors):
You can run one of the pythonOCC samples. The PyQt4 package should be automatically detected. For instance, running the Geometry.py sample (/samples/Level1/Geometry) :


Note that you might want to find the location of python site-packages with a command like:
python -c “from distutils.sysconfig import get_python_lib; print get_python_lib()”
Mine are under:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
I have installed and re-installed different versions of python and I can never remember where site-packages actually are.
I am trying to follow along, but I’m really confused about the mixing of different versions of Python and Qt between OSX, Fink and Macports.
Because I wanted a simple start, I used your binary packages. This is fine for OCC and PythonOCC (thank you!!!)
> So I can call Python (which one? I guess the 2.6 version from OSX) and I can call “from OCC import *” with no errors.
But PyQt4 is confusing me. To use your binary package of PyQt4, it required Python 2.6 (from OSX) and qt4-x11, for which you suggested Fink. So I installed Fink (had to compile as no binary is available for Snow Leopard).
“fink install qt4-x11″ is humming along, but insists to also install Python 2.5 and Python 2.6 with it. Are they different than the OSX version? Which one will be used and where to put the precompiled PyQt4 packages?
So which version of Python is required with which version of Qt?
(To make it more complicated, I also installed MacPorts for another application which installed qt4-mac with it. Not qt4-x11. And from there I can install PyQt4 but that one uses qt4-mac.)
–> So rather than starting all over, is there a foolproof combination of libraries (Qt4, Python and PyQt4) that works?
Stefan,
The pythonOCC binaries only need the ‘standard’ MacOSX python 2.6.
PyQt needs python2.6 and qt4-x11. (the -x11 is *very* important since OpenCASCADE is built upon x11).
Fink is weird: I don’t understand why there are so many dependencies coming with qt4-x11. It was the same for me: I have dozains of unuseful packages, but fink absolutely wanted to installed them. But I don’t actually use fink’s python (2.5 nor 2.6). I only use the standard Python that comes with 10.6
Qt4-x11 is installed through Fink and I’ve used your binary package. So far, so good…
Alas, when trying to run python and test “from PyQt4.QtCore import *” it finds the dylib, but complains about wrong architecture! Why is this so troublesome?
Maybe I should install PyQt4 (but then I fear, it will be hard to decide which Python it should use and which qt4 (the one from Fink I suppose).
Are you sure your Python is set up in 64bit mode?
>>> import sys
>>> sys.maxint
9223372036854775807
>>>
If the result is not 9223372036854775807, then your python is 32 bit, and as a consequence not compliant with pythonOCC (compiled for 64 bits systems).
You can switch from 32/64 bits python (‘man python’):
“”"
64-BIT SUPPORT
Versions 2.6 and 3.0 support 64-bit execution (which is on by default). Version 2.5 only supports 32-bit execution.
Like the version of Python, the python command can select between 32 and 64-bit execution (when both are available).
Use:
% defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
to make 32-bit execution the user default (using `/Library/Preferences/com.apple.versioner.python’ will set the sys-
tem-wide default). The environment variable VERSIONER_PYTHON_PREFER_32_BIT can also be used (has precedence over the
preference file):
% export VERSIONER_PYTHON_PREFER_32_BIT=yes # Bourne-like shells
or
% setenv VERSIONER_PYTHON_PREFER_32_BIT yes # C-like shells
Again, the preference setting and environmental variable applies to both python and pythonw.
“”
After checking this issue, it appears that the qt4-x11 libraries are “i386″. Damn. I am getting the thought that all of fink was built as 32-bit. I’ll let you know it this solves matters
I have bad luck. I re-installed fink, now to be sure to use 64-bit libraries. But installing qt4-x11 fails, when trying to install one of the dependencies (something with “shared-mime-info”).
FWIW, it works fine on my Windows Desktop PC.
The saga continues… After failing to compile shared-mime-info and finding several people complain about the same prolbem, I removed the whole of fink and renamed /usr/local/lib and /usr/local/bin to not interfere with compilation. I also removed Macports to ensure that it didn’t interfere (and to reclaim 6 GB hard disk space along with it).
Then re-installed fink from source, ensured 64-bit and enabled the unstable branch. Called the fink environment script (
source /sw/bin/init.sh), updated all and called scanpackages.All went fine (no real surprises here).
Then started with the problematic
fink --no-use-binary-dist install shared-mime-infoand chose “db47-shlibs” without “aes” when asked. I chose the aes-versions with last attempts which failed. Don’t know if this was the reason of the failure, though. And don’t know if the “no-use-binary” helped. Last attempt ended with an Expat bundle that didn’t link to expat1.dylib and thus missed a required symbol. I installed MacDependency which is more convenient than otool (and I used Dependency Checker on Windows quite a lot in the past).This finally succeeded. Don’t know which tricked my system into it
And the install of
fink install qt4-x11succeeded as well (but took a long time). Also chose non-aes libraries when asked. I can launchqmake -vanddesignerso this seems to work fine.Now I can launch Python (it says 2.6.1) and load the OCC libraries with no error. But loading PyQt4 failed.
Symbol not found: __ZN28QCoreXmlStreamEntityResolver13resolveEntityERK7QStringS2_Referenced from: /Library/Python/2.6/site-packages/PyQt4/QtCore.so
Expected in: /sw/lib/qt4-x11/lib/libQtCore.4.dylib
in /Library/Python/2.6/site-packages/PyQt4/QtCore.so
So I then compiled pyqt4 from fink.
fink install pyqt4-py26, which took again, quite some time. But it worked.I also had to
fink install pythonto get thepython2.6command to invoke the Fink python installation. That recognizes PyQt4, but now OCC is not found (as this is installed in the Apple Python… Sigh.So I copied OCC (the pre-compile PythonOCC) into “/sw/lib/python2.6/site-packages” and launched python again. Now it complains about a version mismatch.
So close, but yet so far…
———
Sorry about making the comments longer than the article itself, but I hope that this can help some people in getting started with PythonOCC (including myself).
It was indeed close… after creating a symbolic link inside the site-packages folder from the system Python 2.6 to the PyQt4 package inside the fink-provided Python 2.6, all fell into place.
So I can now say that I finally can run PythonOCC with Qt (X11) as a backend for GUI. Now the next step is the wxWidgets stuff…