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

前端 未结 4 1827
刺人心
刺人心 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:15

    You need to install the module using your python2.7 installation. Pointing your PYTHONPATH at stuff installed under 2.6 to run under 2.7 is a Bad Idea.

    Depending on how you want to install it, do something like python2.7 setup.py or easy_install-2.7 opencv to install.

    fwiw, on OS X the modules are usually installed under /System/Library/Frameworks/Python.framework/ but you should almost never need to know where anything installed in your site packages is physically located; if Python can't find them without help you've installed them wrong.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-02-06 16:25

    I searched and tried installing opencv3 with python3 for 3 days. Some links suggest for Brew and some virtual env, some say install xcode but all failed in my case. Dont use linux steps to instal opencv-python on Mac. Problem with Mac is Python 2.7 is already installed by Mac. On top of that installing and linking all site-packages is little problematic and we end up with errors.

    I'll share what I did: easy steps to install complete package opencv3, numpy, matplotlib, notebook, spyder etc.. on Mac.

    1. Install anaconda, it creates a directory and install everything inside that use this link -> https://www.continuum.io/downloads download command-line-install

    2. After download, goto terminal and download location of anaconda. $ bash Anaconda3-4.3.0-MacOSX-x86_64.sh

    3. Installation will ask you to append path to .bash_profile >> say yes

    4. Goto home directory, run .bash_profile $ source .bash_profile

    5. check python, should be pointing to $ which python $ /.../anaconda/bin/python

    6. Last step $ pip install opencv-pyhton

    $ python

    $ import cv2

    if no errors, we are good to go.

    0 讨论(0)
  • 2021-02-06 16:26

    Installing OpenCV with Homebrew

    brew tap homebrew/homebrew-science
    brew install opencv
    

    Setting up Python

    Depending on your install location - OS X Default

    cd /Library/Python/2.7/site-packages/
    

    or - Homebrew Python

    cd /usr/local/lib/python2.7
    

    Then create the symbolic link

    ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv.py cv.py
    ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv2.so cv2.so
    

    The above method sourced from a blog post.

    0 讨论(0)
提交回复
热议问题