Robert Valencia
Robert Valencia

Reputation: 1752

Python/OS X: Installed OpenCV from source, but import cv2 results in ImportError

I downloaded the OpenCV source tarball from http://sourceforge.net/projects/opencvlibrary, and I performed the following steps:

  1. Decompressed the tarball
  2. cd ~/opencv
  3. mkdir release
  4. cd release
  5. cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
  6. make
  7. sudo make install

Now, when I try to do import cv2 I get an ImportError:

ImportError: No module named cv2

NOTE: This is for Mac OS X

Upvotes: 0

Views: 485

Answers (2)

Robert Valencia
Robert Valencia

Reputation: 1752

As of this writing, following these instructions successfully installed Python opencv on Mac OS X for me: http://www.pyimagesearch.com/2016/11/28/macos-install-opencv-3-and-python-2-7/

There is an older version of that tutorial, but it had issues with macOS Sierra, so make sure you are following the most recent version. Also, be careful not to just copy and paste everything, especially commands with arguments or flags with situation-specific values, such as paths. For example, if you are not using virtualenv, make sure to replace the virtualenv-based paths with your local Python installation paths. This is particularly important when filling out the cmake flag fields when you get to that step.

Also, as Quang Hoang mentioned, doing brew install opencv3 --with-python could be a faster alternative.

Upvotes: 0

Muhammad Haseeb Khan
Muhammad Haseeb Khan

Reputation: 965

I recommend to download the whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/

  1. open the site
  2. find and search the opencv
  3. download the whl files according to your pc specs
  4. download

Open the cmd in directory in which whl file is installed and type:

pip install file-name.whl

It worked for me, I hope it will work for you too.

Upvotes: 0

Related Questions