How to properly install Python on OSX for use with OpenCV?

前端 未结 4 1824
刺人心
刺人心 2021-02-06 15:38

I spent the past couple of days trying to get opencv to work with my Python 2.7 install. I kept getting an error saying that opencv module was not found whenever I try \"import

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 16:18

    I spent a couple days on this myself. For me, the problem was that that OpenCV installer was not finding the right python installation. It was defaulting to the MacOS-installed version despite the fact that I had upgraded python with homebrew and was using a virtualenv for python. I have collected most of my setup in a gist here: https://gist.github.com/4150916

    Use homebrew to get all the dependencies, but then download the OpenCV tarball and compile yourself being sure to specify all the python related configuration options.

    Assuming a virtualenv named 'opencv'...

    cd OpenCV-2.4.3/
    mkdir release
    cd release
    cmake -D PYTHON_EXECUTABLE=$WORKON_HOME/opencv/bin/python \
     -D PYTHON_PACKAGES_PATH=$WORKON_HOME/opencv/lib/python2.7/site-packages \
     -D INSTALL_PYTHON_EXAMPLES=ON\
     -D PYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Headers\
     -D PYTHON_LIBRARY=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib\
    ..
    make -j8
    make install
    

提交回复
热议问题