简体   繁体   中英

OpenCV in python on mac installation with homebrew

I'm trying to get opencv for python on my mac running mavericks. After googling/stack overflow seraching I tried:

brew install homebrew/science/opencv

Based on the terminal output it looks like that worked.

To verify I wrote a python script that simply contains:

import cv2

print("Hello")

I get no module named cv2 . When I try looking at the installed modules by typing help('modules') I don't see cv or cv2. This leaves me with two conclusions: either I didn't properly install opencv or import cv2 isn't actually importing cv2 and python is looking in the wrong location for cv2. Any suggestions would be appreciated.

根据本指南 ,如果您将以下内容添加到.bash_profile它应该可以解决您的问题:

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

You could update your pythonpath, but you would probably be better served running 'brew install python' so that you are not using system python. System python and brewed python look for modules in different locations.

EDIT: Asked questions, updated the above.

This worked for me. Install X code from App Store.

  1. Uninstall Homebrew
  2. Uninstall and clean Anaconda
  3. Reinstall Anaconda and Homebrew
  4. Install OpenCV using conda install -c menpo opencv3

It should be good to go. Remember import it as import cv2 In case of any library errors try this conda install -c conda-forge basemap fiona

Hope it helped

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM