How to install Python 2.7 bindings for OpenCV using MacPorts

早过忘川 提交于 2019-12-17 22:42:30

问题


When trying to "import cv" in python I get: "ImportError: No module named cv". This question has appeared in many forms, but I haven't found the answer that helps.

On my Mac OS X Lion, among many other ports, I have run:

sudo port install python27

and

sudo port install opencv +python27

Running:

port select python

I see: "python27 (active)"

And running:

port installed opencv

I see: "opencv @2.3.1a_1+python27 (active)"

What else should I check? Thanks.


回答1:


I had this same problem. It looks like a (maybe?) bug with the OpenCV install script for 2.3.1a. It will not create the Python bindings unless NumPy is already installed.

To fix it:

sudo port uninstall opencv
sudo port install py27-numpy
sudo port install opencv +python27

That worked for me! I found this by doing some Googling, and the correct answer was here: wbarczynski.org/wp/2011/11/25/opencv-with-py-bindings-on-mac-with-macports-intall-numpy-first/




回答2:


STEP ONE

Use Macports to install opencv.

STEP TWO

Put these two files somewhere on your PYTHONPATH (for example in your site-packages):

  • https://github.com/jonmrodriguez/opencv-2.3-new-python-bindings/blob/master/cv.py
  • https://github.com/jonmrodriguez/opencv-2.3-new-python-bindings/blob/master/cv2.so

STEP THREE

Create the below soft links (because cv2.so expects the dylibs to be in /usr/local but MacPorts installs to /opt/local):

cd /usr/local/lib/
ln -s /opt/local/lib/libopencv_core.2.3.dylib libopencv_core.2.3.dylib
ln -s /opt/local/lib/libopencv_flann.2.3.dylib libopencv_flann.2.3.dylib
ln -s /opt/local/lib/libopencv_imgproc.2.3.dylib libopencv_imgproc.2.3.dylib
ln -s /opt/local/lib/libopencv_video.2.3.dylib libopencv_video.2.3.dylib
ln -s /opt/local/lib/libopencv_ml.2.3.dylib libopencv_ml.2.3.dylib
ln -s /opt/local/lib/libopencv_features2d.2.3.dylib libopencv_features2d.2.3.dylib
ln -s /opt/local/lib/libopencv_highgui.2.3.dylib libopencv_highgui.2.3.dylib
ln -s /opt/local/lib/libopencv_calib3d.2.3.dylib libopencv_calib3d.2.3.dylib
ln -s /opt/local/lib/libopencv_objdetect.2.3.dylib libopencv_objdetect.2.3.dylib
ln -s /opt/local/lib/libopencv_legacy.2.3.dylib libopencv_legacy.2.3.dylib
ln -s /opt/local/lib/libopencv_contrib.2.3.dylib libopencv_contrib.2.3.dylib



回答3:


I was wondering if you have installed opencv to the OSX version of the python instead of macports.

have you tried easy install, I normally use easy_install to install the packages.

/opt/local/bin/easy_install-2.7 opencv


来源:https://stackoverflow.com/questions/8410443/how-to-install-python-2-7-bindings-for-opencv-using-macports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!