How to install Python on OSX for use with OpenCV?

I spent the last couple of days trying to get opencv to work with my Python 2.7 installation. I was always mistaken in saying that the opencv module was not found when I try to "import cv".

Then I decided to try installing opencv using Macports, but that didn't work.

Then I tried Homebrew, but that didn't work either.

In the end, I found that I should change PYTHONPATH as such: export PYTHONPATH = "/usr/local/lib/python2.6/site-packages/: $ PYTHONPATH"

My problem is that I did not find / usr / local / lib / python 2. * ... etc The folder just doesn't exist

So my question is: How do I properly install Python on OS X Snow Leopard so that it works with opencv?

Thank you very much,

+4
source share
4 answers

I spent a couple of days on it myself. For me, the problem was that the OpenCV installer could not find the correct python installation. It did not install MacOS, despite the fact that I updated python using homebrew and used virtualenv for python. I put together most of my setup at the core: https://gist.github.com/4150916

Use homebrew to get all the dependencies, but then download the OpenCV tar file and compile yourself, do not forget to specify all configuration parameters related to python.

Assuming 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 
+7
source

You need to install the module using python2.7 installation. Pointing your PYTHONPATH to things set under 2.6 to work 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 modules are usually installed in /System/Library/Frameworks/Python.framework/, but you hardly need to know where everything that is installed in your site packages is physically located; if Python cannot find them without help, you installed them incorrectly.

+2
source

Install OpenCV with Homebrew

 brew tap homebrew/homebrew-science brew install opencv 

Python setup

Depending on the installation location - OS X Default

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

or - Homebrew Python

 cd /usr/local/lib/python2.7 

Then create a symlink

 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 is obtained from the message.

+1
source

I searched and tried to install opencv3 with python3 for 3 days. Some links offer for Brew and some virtual env, some say that install xcode, but all failed in my case. Do not use linux steps to install opencv-python on Mac. The problem with the Mac is that Python 2.7 already has a Mac installed. In addition, the installation and layout of all site packages is a little problematic, and we get errors.

I will tell you what I did: simple steps to install the full package opencv3, numpy, matplotlib, laptop, spyder, etc. on a Mac.

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

  • After downloading, go to the terminal and download the anaconda location. $ bash Anaconda3-4.3.0-MacOSX-x86_64.sh

  • Installation will ask you to add the path to .bash_profile -> say yes

  • Open your home directory, run .bash_profile $ source.bash_profile

  • check python should point to $ python $ / ... / anaconda / bin / python

  • Last step $ pip install opencv-pyhton

$ python

$ import cv2

If there are no errors, we will be happy.

+1
source

All Articles