Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing opencv 3.1 with anaconda python3?

How do I install opencv with anaconda python3 , opencv picked up my python3 executables

--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.12)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
--     packages path:               lib/python2.7/dist-packages
-- 
--   Python 3:
--     Interpreter:                 /home/tamim/anaconda3/bin/python3 (ver 3.5.2)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.5m.so (ver 3.5.2)
--     numpy:                       /home/tamim/anaconda3/lib/python3.5/site-packages/numpy/core/include (ver 1.11.1)
--     packages path:               lib/python3.5/site-packages
-- 
--   Python (for build):            /usr/bin/python2.7

I installed opencv with the following make options

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" ..

But after installing it I can't import cv2 within python3 of anaconda. I can however import cv2 from builtin python2 command. So I suppose it build for the python2 version as stated in the last line.

How do I build for anaconda python3 ?

like image 831
Tamim Addari Avatar asked Aug 05 '16 11:08

Tamim Addari


People also ask

Is OpenCV compatible with python 3?

The nice thing with OpenCV is that it comes with a complete Python 3 library. The latest GeeXlab 0.29. 17.0 for Windows 64-bit comes with Python 3.8.

Does anaconda include OpenCV?

There's nothing with anaconda that prevents you from using it with opencv. It's just not included in the conda install except for linux. You can get install binaries files from here for windows.


2 Answers

I think you don't need to build OpenCV for anaconda, there is this very handy tool called 'conda' that is available in your terminal once you have installed the Anaconda python distribution.

I found this site which gives instruction on how to install opencv3

https://anaconda.org/menpo/opencv3

I personally installed it myself so just try follow along with these instructions.

If you have the Anaconda python distribution installed in your system, you can issue this command (assuming you are working on linux) fire up the terminal:

conda install -c menpo opencv

If the version of python install in your Anaconda is 2.7, the command above should install OpenCV 3.1, but if the version of your python is 3.5, then you should change 'opencv' in the last line to 'opencv3'

conda install -c menpo opencv3

This should install OpenCV in your Anaconda. To see if you have installed it successfully, fire up your Python and issue the following command:

import cv2 # import the opencv library

cv2.__version__ # this will print the version of your opencv3

Hope that helps =)

like image 173
stevenferrer Avatar answered Oct 16 '22 19:10

stevenferrer


If you are getting an error like the following:

    UnsatisfiableError: The following specifications were found to be in conflict:
            opencv 2.4.11* -> numpy 1.9* -> python 2.6* -> openssl 1.0.1*
            python 3.6*
            Use "conda info " to see the dependencies for each package.

Just install python 3.5 and try again.

conda install python=3.5
conda install -c menpo opencv  # whichever
conda install -c menpo opencv3 # you need
like image 24
mimoralea Avatar answered Oct 16 '22 19:10

mimoralea