Ask Your Question
0

OpenCV with Python on a mac

asked 2015-03-29 09:12:56 -0600

Hardin gravatar image

Hello everybody. I would appreciate if someone can help me with this.

I have installed Opencv with python on a windows PC. No problem, I am trying to do the same on a mac. (snow leopard)

However, I did the following: -Installed python 2.7 ( i know mac comes with python but i got recommended that i had to reinstall it) -Installed Numpy

So if I do something like "import numpy as np" in python, no problem.

Then I wanted to install opencv and the only option seemed MacPorts so I installed Macports and then did the

sudo port install opencv +python2.7 (sorry I dont remember exactly the grammar now)

Well, it seems that opencv is working. I made a program in C++ and build it and could get to display a jpg in a window. So no problem my opencv is working for C++

now I try to do that with python but even though I make import cv2 I get

import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named cv2

What should I do for python to recognize my opencv??

Thanks a thousand

F.Y.I I did the following: $port select python Available versions for python: none (active) python25-apple python26-apple python27

$ port installed opencv The following ports are currently installed: opencv @2.4.11_0+python27 (active)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-03-29 20:10:54 -0600

KansaiRobot gravatar image

by seeing the port select, it is clear that python27 is not selected. So first do the following:

sudo port select --set python python27

Then open your .bash_profile with

open -t ~/.bash_profile

and add the following line:

export PYTHONPATH=<path where cv2.so is located>:$PYTHONPATH

This path can vary. in my case it was located in

/opt/local/Library/Frameworks/Python.framework/versions/2.7/lib/Python2.7/site-packages

Once you save the bash_profile close your terminal and open it again.

Then try python and the import cv2 line and voila!

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2015-03-29 09:12:56 -0600

Seen: 6,588 times

Last updated: Mar 29 '15