Installing PyOpenCL on Mac OS X
Contents
This tutorial will walk you through the process of building PyOpenCL. To follow, you really only need two basic things:
Mac OS X >= 10.6 (Snow Leopard).
XCode >= 3.2
In addition, PyOpenCL's installation process will automatically download py.test 1.0.2 or newer and pytools. If you are installing without web access, you need to download these packages manually and stick them in the package's root directory before installing.
There is also a complete installation walkthrough for a python, numpy, scipy, boost and pyopencl build from source.
Step 1: Install Boost
You may already have a working copy of the Boost C++ libraries. If so, make sure that it's version 1.35.0 or newer. If not, no problem, please follow the simple BoostInstallationHowto. Continue here when you're done. Boost 1.40 worked at the time this guide was written.
Step 2: Download and unpack PyOpenCL
Download PyOpenCL and unpack it:
$ tar xfz pyopencl-VERSION.tar.gz
(You need version 0.90.1 or newer.)
Step 3: Check NumPy
Mac OS X 10.6 includes an install of NumPy 1.2.1 in the following location (/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/). This NumPy install works fine with PyOpenCL 0.90.x, therefore if you're Python 2.6 provided by Apple in Mac OS X 10.6 you needn't do anything extra at this step.
If you have installed a newer version of NumPy and are using Python 2.6.1 from Apple you need to ensure that both the build and your running Python environment both are using the custom-installed NumPy. Check the version that python will import by default using the following command
$ python -c "import numpy; print numpy.version.version"
If you don't see your updated NumPy install listed there, you may need to adjust your PYTHONPATH as follows:
$ export PYTHONPATH=/Library/Python/2.6/site-packages:$PYTHONPATH
(to make this more permanent, add it to your ~/.bash_profile if using bash as your shell or your ~/.zshrc if using ZSH)
Step 4: Build PyOpenCL
Next, just type:
$ cd pyopencl-VERSION # if you're not there already $ python configure.py \ --boost-inc-dir=$HOME/pool/include \ --boost-lib-dir=$HOME/pool/lib \ --boost-python-libname=boost_python \ --boost-thread-libname=boost_thread \ --cl-libname='' \ --ldflags='-Wl,-framework,OpenCL' \ --boost-compiler='gcc42' $ make $ sudo make install
Note: You may find that the boost libraries installed into the $HOME/pool/lib directory are not just named boost_python.dylib and boost_thread.dylib, and may include version information for the GCC used in their filenames. If you find this is the case, you may want to replace the --booost-*-libname lines above with ones like the following:
--boost-python-libname=boost_python-xgcc42-mt \ --boost-thread-libname=boost_thread-xgcc42-mt \
Once that works, congratulations! You've successfully built PyOpenCL.
Note, if you've installed boost as described on the linked page, you'll need to either do this before using PyOpenCL:
$ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$HOME/pool/lib
(you can add this to your .profile (default OS X shell), .bash_profile, .zshrc, etc..)
Or, you could vary the boost instructions to install boost for all users on the system.
