Installing PyOpenCL on Mac OS X

[[!toc ]]

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.

Step 1: Download and unpack PyOpenCL

From git:


git clone http://git.tiker.net/trees/pyopencl.git
cd pyopencl
git submodule init
git submodule update

From tar file: (((Information below may be wrong and need fixing)))

[[!PyPi pyopencl desc="Download PyOpenCL"]] and unpack it:


$ tar xfz pyopencl-VERSION.tar.gz

(You need version 0.90.1 or newer.)

Step 2: 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 3: Build PyOpenCL

Next, just type:


$ cd pyopencl-VERSION #2012.1 if you're not there already
$ python configure.py
$ make
$ sudo make install

Once that works, congratulations! You've successfully built PyOpenCL.

Make sure you restart your shell before attempting to import pyopencl.

Note that this step may automatically look for and, if necessary, install a number of Python packages from the Python package index. These packages are listed under install_requires in PyOpenCL's install control file.

Optional: Boost C++ Libraries

As of version 0.92, the Boost C++ libraries are no longer a dependency of PyOpenCL.

If you would like to use multiple packages that use Boost.Python (e.g. both PyCUDA and PyOpenCL), you can still build PyOpenCL against a separate Boost installation. If so, follow the BoostInstallationHowto. Continue here when you're done.

You may use the following configure/build snippet to specify where you installed Boost:


$ 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 --boost-*-libname lines above with ones like the following:


  --boost-python-libname=boost_python-xgcc42-mt \
  --boost-thread-libname=boost_thread-xgcc42-mt \

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.

Optional: OpenGL Interop

Support for OpenGL interoperation with OpenCL (sharing buffers) is available in the latest revision of the git repository:


git clone http://git.tiker.net/trees/pyopencl.git

If you don't have boost already installed, you can do the following to obtain a subset of boost to build against


git submodule init
git submodule update

To turn on OpenGL interop you run configure with the following option:


python configure.py --cl-enable-gl

Note that to use it you will need PyOpenGL

Now you should be able to run the example:


python examples/gl_interop_demo.py

OSX Lion

May 2012

This is just a note to confirm PyOpenCL is building and working correctly with:

OSX Lion, XCode 4.3.2

My mac is an iMac 27" 2010 model with a Radeon HD 4850 GPU, and an Intel i5 processor

I have used the following steps:


git clone http://git.tiker.net/trees/pyopencl.git
cd pyopencl
git submodule init
git submodule update
python configure.py
python setup.py build
make
sudo python setup.py install

If you get the following error, just run the last install command again and you're set.

 src/wrapper/wrap_cl.hpp:14:10: fatal error: 'OpenCL/opencl.h' file not found #include  

  • ^ 1 error generated. error: Setup script exited with error: command '/usr/bin/clang' failed with exit status 1 }}}

PyOpenCL sees both the GPU and CPU and tests correctly

OSX Maveriks 10.9.1

Feb 2014

This is just a note to confirm that the above instructions for PyOpenCL on Lion work equally well on Maveriks:

Test System:

Computer: Mini Mac Intel Core i5 Late 2012

OS: OSX Maveriks 10.9.1

Compiling Tools: XCode 5.0.2

No discreete GPU , but using the Intel HD4000 embedded onboard of the i5 processor

I have used the following steps (as for Lion):


git clone http://git.tiker.net/trees/pyopencl.git
cd pyopencl
git submodule init
git submodule update
python configure.py
python setup.py build
make
sudo python setup.py install

One warning was generated several times during compilation, but everything looks OK

OSX Yosemite 10.10.1

Jan 2015

This note is just to confirm that PyOpenCL works on OSX 10.10.1

Test system:

OSX 10.10.1

XCode 6.1.1

Using python from Homebrew (so no need for sudo).


pip install numpy # Installs version 1.9
git clone http://git.tiker.net/trees/pyopencl.git
cd pyopencl
git submodule init
git submodule update
python configure.py
python setup.py build
make
python setup.py install

OSX ElCapitan 10.11.6

Aug 2016

Short note: installation works in a virtualenv:


git clone http://git.tiker.net/trees/pyopencl.git
cd pyopencl
git submodule init
git submodule update

cd $VIRTUALENV_BASE_DIRECTORY
source venv/bin/activate
cd -

python configure.py
python setup.py build
make -j 4
python setup.py install
cd ../
python -c "import pyopencl"


CategoryPyOpenCl