I have been struggling to get working OpenCV library for my Python on Mac Snow Leopard, and i think it might be helpful to show how i did it. I am aware that there are many blogs about this issue, and plenty of them are doing the same. I have been reading many blogs about this problem, and i have learned some stuff too, and finally i have done it! I remember being so excited about my first sample actually running…

In case you don’t want to use MacPorts for downloading the library for any reason, this might be helpful for you. i was not using MacPorts for it, because i had problems getting all prerequisites for OpenCV Library, so i had to do it some other way.
I must admit, that most helpful article was official install guide from OpenCV wiki.
  1. Currently the latest version of Python is 3.1.2, but i am using pre-installed 2.6.1. There is nothing wrong with neither version, so go ahead and install it from their download site. They have regular installer for it, so no need to explain anything here… 
  2. Now go and download OpenCV Library from SourceForge download site.
  3. Unarchive it to some well placed directory… open terminal and navigate there.
    While in directory suitable for installing (containing files like CMakeLists.txt or any familiar files containing word “install” in them 😉 ) create folder “release

    mkdir release

    and navigate to it

    cd release 

  4. Put

    ccmake

    to the terminal to configure your release. Search for anything including “python” and mark it with YES. You can navigate to next line with ctrl+n and change the setting with Enter. After checking all the options, hit “c” for configure and after that “g” to generate the config file. now you can exit ccmake interface.

  5. Enter

    sudo make -j8

    and wait for a while… then

    sudo make install

    and you are almost there 🙂

  6. At this point you have installed Python, OpenCV but they might not know about each other… open /etc/bashrc for example with vim and at the end put this

    export PYTHONPATH=/path/to/your/OpenCV-2.1.0/release/lib:$PYTHONPATH 
    export PYTHONPATH=/usr/local/lib/python2.6/site-packages/cv.so:$PYTHONPATH

    – use versions suitable for you, but make sure you are entering the right folder.
    – i have found on web that variable DYLD_LIBRARY_PATH is also important, but i don’t use it and mine works… so in case your library won’t try setting it like the first line of PYTHONPATH variable.

  7. To test if that worked, just type

    python

    into terminal, and then

    import cv

    or

    import * from opencv

    into python console. It should not give you negative feedback about not existing module. 

#. In case it still gives you

ImportError: No module named cv

go back to point 4 about configuring your OpenCV release and check all values carefully… i had to do it several times… then make and install it again and it should work 🙂

##. You might need to download and install cmake for this, in case you don’t have one. I downloaded mine from

http://www.cmake.org/cmake/resources/software.html

and it was a regular package installation, so i guess you don’t need any assistance there.

I hope that at least for some of you was my article helpful and i would be glad to hear it, or even if it did not work, so i can make any changes…
Facebook Comments
OpenCV / Python / MAC
Tagged on:

One thought on “OpenCV / Python / MAC

  • 28. March 2016 at 10:46
    Permalink

    Thank you for sharing your info. I truly appreciate your efforts and I will be
    waiting for your further write ups thanks once again.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *