Category Archives: MacOS

How to build OpenCV with GPU support via MacPorts in OS X 10.8

First thing first, install the NVIDIA CUDA libraries from (take notice that last night, OS X 10.9 Mavericks has got its update too!)

Second, open Terminal and add the two paths below

export PATH=/Developer/NVIDIA/CUDA-5.5/bin:$PATH

if previously installed, uninstall opencv.

sudo port uninstall opencv @

If you have a different version installed, MacPorts will tell you and you’ll need to change the one above with your own, of course. Now you need to edit the opencv’s portfile

sudo port edit --editor nano opencv

nano will open up, scroll down and change the appropriate settings to


and optionally


you “could” also add


(although I’m not completely sure this is the right syntax for cusparse though! Please do let me know if this is the case)

Now, it’s time to clean the previous installation

sudo port clean opencv

And at last, type

sudo port upgrade -s -n --force opencv

to rebuild the amended portfile. The flag -n avoids rebuilding of the dependencies and -s starts building from the source code only with no binaries whatsoever and now you can go get yourself a cuppa, even two, as this step will take a bit (about half a hour on a rMBP).

These links below can be helpful too:


How to switch between multiple MacOS X Python framework versions

This is mainly a note-for-self kinda post.

I’ve got multiple Python framework versions installed in my Mac, including MacPorts’ versions.

If I need to switch between MacPorts versions, I can use the usual

sudo port select python python26
sudo port select python python27

but if I need to switch to a MacPython version then I have to update the PATH manually like this.

export PATH

At this point, I can type   which python  in the shell and check whether the path has been changed.

To revert back to the MacPorts version, I will use

export PATH

Again, you can double-check by typing   which python  in the shell.

Now, what I’ve noticed is that at this point the

sudo port select python python27

won’t take effect anymore. I mean after the PATH has been manually changed, MacPorts above command doesn’t seem to be any longer effective although it said it succeeds in doing the selection. That means that manually changing the PATH may have compromised the port selection functionality in some ways, please let me know if you’ve got a clue of what might’ve happened to it.

That’s all. Err, not yet. I found this blog post very helpful.