ImportError: No module named 'cv2' in OSX for OpenCV3 using Python3.5.2

asked 2016-08-04 19:47:44 -0500

monajalal gravatar image

I have installed opencv3 with Python3 using this command:

brew install opencv3 --with-python3 --with-contrib

I get this:

bash-4.3$ brew info opencv3
homebrew/science/opencv3: stable 3.1.0 (bottled), HEAD [keg-only]
Open source computer vision library, version 3
http://opencv.org/
/usr/local/Cellar/opencv3/3.1.0_3 (479 files, 130.7M)
  Built from source on 2016-08-04 at 19:23:10 with: --with-python3 --with-contrib
From: https://github.com/Homebrew/homebrew-science/blob/master/opencv3.rb
==> Dependencies
Build: cmake ✔, pkg-config ✔
Required: jpeg ✔, libpng ✔, libtiff ✔
Recommended: eigen ✔, openexr ✔, homebrew/python/numpy ✔
Optional: ffmpeg ✔, gphoto2 ✘, gstreamer ✘, jasper ✘, libdc1394 ✘, openni ✘, openni2 ✘, qt ✔, qt5 ✘, tbb ✔, vtk ✔
==> Options
--32-bit
    Build 32-bit only
--c++11
    Build using C++11 mode
--with-contrib
    Build "extra" contributed modules
--with-cuda
    Build with CUDA v7.0+ support
--with-examples
    Install C and python examples (sources)
--with-ffmpeg
    Build with ffmpeg support
--with-gphoto2
    Build with gphoto2 support
--with-gstreamer
    Build with gstreamer support
--with-jasper
    Build with jasper support
--with-java
    Build with Java support
--with-libdc1394
    Build with libdc1394 support
--with-opengl
    Build with OpenGL support (must use --with-qt5)
--with-openni
    Build with openni support
--with-openni2
    Build with openni2 support
--with-python3
    Build with python3 support
--with-qt
    Build the Qt4 backend to HighGUI
--with-qt5
    Build the Qt5 backend to HighGUI
--with-quicktime
    Use QuickTime for Video I/O instead of QTKit
--with-static
    Build static libraries
--with-tbb
    Enable parallel code in OpenCV using Intel TBB
--with-vtk
    Build with vtk support
--without-eigen
    Build without eigen support
--without-numpy
    Use a numpy you've installed yourself instead of a Homebrew-packaged numpy
--without-opencl
    Disable GPU code in OpenCV using OpenCL
--without-openexr
    Build without openexr support
--without-python
    Build without Python support
--without-test
    Build without accuracy & performance tests
--HEAD
    Install HEAD version
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

opencv3 and opencv install many of the same files.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/opencv3/lib
    CPPFLAGS: -I/usr/local/opt/opencv3/include


If you need Python to find bindings for this keg-only formula, run:
  echo /usr/local/opt/opencv3/lib/python2.7/site-packages >> /usr/local/lib/python2.7/site-packages/opencv3.pth

I have this version of python:

bash-4.3$ python
Python 3.5.2 (default, Jul 28 2016, 21:28:00)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/Library/Frameworks/Python.framework/Versions/3.4/bin', '/Users/mona', '/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', '/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5', '/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', '/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/site-packages', '/usr/local ...
(more)
edit retag flag offensive close merge delete

Comments

You have conflict between python 3.4 and 3.5. Try to completely remove both (including headers and libraries) and install one from brew (including numpy).

mshabunin gravatar imagemshabunin ( 2016-08-09 08:41:54 -0500 )edit