Can't get OpenCV to work with Python on a Mac - python

I am having trouble getting OpenCV to work with Python on my Mac.
I have tried installing it with MacPorts and with Cmake (which I installed from MacPorts) using the methods found at here: http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port. I also had to download Xcode to make MacPorts work.
I ran sudo port -v install opencv +python27 and it seemed to work fine. However when I tried to import OpenCV in Python using import cv, the module could not be found.
If any of this information helps, I have OSX 10.6.8 Snow Leopard, python 2.7.3, and am trying to install OpenCV 2.4.3. I am not a very experienced programmer so my troubleshooting attempts are falling short of a solution.
Any help is appreciated. Thanks!

I haven't tried the MacPorts installation, but you might want to try this:
import cv2
from cv2.cv import *

I had the same problem, it seems that the OpenCV Python Bindings don't get installed without numpy preinstalled; you can use these commands:
sudo port uninstall opencv
sudo port install py27-numpy
sudo port install opencv +python27
As in this question: How to install Python 2.7 bindings for OpenCV using MacPorts

Related

installing opencv for python 2.7 on a MAC

I installed opencv via the command pip install opencv-python and then when I import cv2 in python I get the error ImportError: dlopen(/Library/Python/2.7/site-packages/cv2/cv2.so, 2): Symbol not found: _clock_gettime
I would like to install opencv for python 2.7 on a mac. How can I resolve this error ? I am using El Capitan.
I installed opencv prior to this using brew install opencv but then I uninstalled it using brew uninstall opencv before using pip.
This works !
sudo pip install opencv-python==3.3.0.10
El Capitan has an issue detailed here http://answers.opencv.org/question/182067/import-cv2-throws-symbol-not-found-_clock_gettime/
In order to circumvent this issue, I rolled back to an earlier version of opencCV.
A trick to check the available version with pip do
sudo pip install opencv-python==
This will return all the available version and then you can try the ones that work for you.
Dont forget to pip uninstall when moving to a different version
It looks like this is an issue with python-opencv and the mac operating system That you are using. From the link below it looks like Apple changed something to do with _clock_gettime function, meaning the maintainers of python-opencv will need to update.
The commenters on the post below managed to fix the issue by upgrading to Sierra
http://answers.opencv.org/question/182067/import-cv2-throws-symbol-not-found-_clock_gettime/

installing opencv for python in Ubuntu 14.04

I ran the following command on terminal
$ sudo apt-get install libopencv-dev python-opencv
This installed opencv version 2.4.10.
After that I open python in terminal and try to import opencv as follows
>> import cv2
This gives me an error :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
I also tried using import cv, import opencv, etc. but I am getting the same error.
Do I need to follow some more steps to configure opencv for python ??
This happens when python cannot refer to your default site-packages folder where you have kept the required python files or libraries
Add these lines in the code:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don't want to add any thing to the code.
OR
try adding the following line in ~/.bashrc
export PATH=/usr/local/lib/python2.7/site-packages:$PATH
This happens when python cannot refer to your default site-packages folder where you have kept the required python files or libraries
Add these lines in the code:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don't want to add any thing to the code.
There is an installer for Ubuntu 16.04, and it may work well on Ubuntu 14.04, you could have a try. I have used it to install on Ubuntu 16.04 and it succeed!
An interactive installing script for install openCV on Ubuntu 16.04 LTS
The Opencv version(2.4.10) installed is for python2x version.
I think you are trying to use cv2 in python3x version (which might be set as default for python)
Open python2 on terminal (use command python2 instead of python)
>> import cv2
This will work.
I think it is better that you just install Anaconda python distribution.
https://www.continuum.io/downloads
You can find wealth of tutorials in the internet on how to install it in your system. And trust me, it is VERY EASY to install.
After you have install your Anaconda python distribution, you can install OpenCV 3.1 by the following commands. Note that you should have an internet connection.
# if you are using Anaconda for Python 2.7
conda install -c menpo opencv
The above code should install OpenCV 3.1 in your anaconda python 2.7
# if you are using Anaconda for Python 3.5
conda install -c menpo opencv3
The above code should install OpenCV 3.1 in your anaconda python 3.5
Then to verify that you have successfully install OpenCV 3.1 in your system, you can issue the following command in the python interpreter:
# import the opencv library
import cv2
# prints the version of the OpenCV installed in your system
cv2.__version__
That's it. I hope that helped you =)
Try using this:
sudo apt-get install python-opencv opencv-dev python-numpy python-dev

unable to install python image library

I want to install pinax on windows, I have to install PIL but can't do so
I'm on windows xp pro 32 bit, sp3, i have python 2.7
EDIT:
i don't know if this is caused by pil or not, but when i type
python scripts/pinax-boot.py ../pinax-env
i see
Install setuptools for windows and it will make your live easier. For example to get PIL you've got to say
easy_install pil
in your windows shell or
easy_install <package_name>
for some other package and get the latest version. Good luck!

Best way to install pygame on OS X Lion?

I tried to install pygame via pip but this fails. Based on my google searches, it sounds like easy_install also fails.
I also checked out: http://www.pygame.org/wiki/MacLionCompile but the solution is incomplete.
I'm running python 2.7.1 bundled with Lion.
Suggestions? Appreciate the help.
You could try the binary package for Lion, available on the pygame website.
It worked for me (OSX 10.7.1 with bundled Python 2.7.1)
See the answer from this question: PyGame in a virtualenv on OS X with brew?
Essentially, the PyGame in PyPy hasn't been updated for a while.
The version in the repository has updated build scripts that handle Pythonbrew, virtualenv and other utilities.
The pip command to use is:
pip install hg+http://bitbucket.org/pygame/pygame
Just for the sake of anyone that googles this question, my lab has a wiki set up with instructions for installing Pygame with just about any configuration:
http://smash.psych.nyu.edu/labwiki/PyGameSetup
I had good luck with macports:
Install macports if you don't already have it: http://www.macports.org/
Install python via macports: sudo port install python26. I typed in the command it said at the end to set it as my default python installation. If you don't, then in step 4 you'll have to run the app a different way.
Install pygame: sudo port install py26-game
Run your pygame app: python main.py
I have been looking for this for myself and I stumbled upon this build that happens to work. I am using OSX 10.8.3 and python 2.7.
http://inside.catlin.edu/moodle/mod/resource/view.php?id=16736

opencv and python in osx - but how?

I tried to install opencv and python with port and brew.
but when i try import cv it says "module not found".
i have the same problem on my windows machine and just no solution works.
is there a simple step by step solution for someone who does not know all the terminal codes?
im not really a good programmer but it would be awsome to get this working.
--edit--
got it working on Windows and Mac
Mac: First uninstalled Homebrew and MacPort
restarted, installed Macport again.
then :
sudo port install opencv +universal +python26
after that i just had to install numpy.
Win7
installed
python-2.7.2.msi
OpenCV-2.2.0-win32.exe
opencv-python-2.2.0.win32-py2.7.exe
numpy-1.6.0-win32-superpack-python2.7.exe
When using brew, try brew info opencv, which explicitly tells you:
The OpenCV Python module will not work until you edit your PYTHONPATH like so:
export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"
The export thing should go into your shell config. You could put this into ~/.bashrc, but the truly system-wide setting would need to be set otherwise (try Setting environment variables in OS X?).
Or else, in your python script:
import sys
sys.path.insert(0, "/usr/local/lib/python2.6/site-packages/")
import cv
Then it should work.
Easiest way (imo) is using macports - once you did setup macports, installing opencv with python is:
port install opencv +python27
(you may need to uninstall opencv first if you already installed it without python support), Then use macport's python (not the system one) - should be in /opt/local/bin/python2.7, you can add that to your path so you don't need to type the full one.

Categories

Resources