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
/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
==> 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
    Build 32-bit only
    Build using C++11 mode
    Build "extra" contributed modules
    Build with CUDA v7.0+ support
    Install C and python examples (sources)
    Build with ffmpeg support
    Build with gphoto2 support
    Build with gstreamer support
    Build with jasper support
    Build with Java support
    Build with libdc1394 support
    Build with OpenGL support (must use --with-qt5)
    Build with openni support
    Build with openni2 support
    Build with python3 support
    Build the Qt4 backend to HighGUI
    Build the Qt5 backend to HighGUI
    Use QuickTime for Video I/O instead of QTKit
    Build static libraries
    Enable parallel code in OpenCV using Intel TBB
    Build with vtk support
    Build without eigen support
    Use a numpy you've installed yourself instead of a Homebrew-packaged numpy
    Disable GPU code in OpenCV using OpenCL
    Build without openexr support
    Build without Python support
    Build without accuracy & performance tests
    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/', '/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 ...
edit retag flag offensive close merge delete


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