I am struggling trying to install OpenCV 3.0.0 with Python3.4.3 and on a virtual env using pyenv. I am on Ubuntu 14.04.
I tried many things using various sources of information: http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/ http://www.pyimagesearch.com/2015/06/29/install-opencv-3-0-and-python-3-4-on-osx/ Running OpenCV from a Python virtualenv How to install ipython qtconsole with pyenv (Python version 3.4.2)
The hard part for me was to link with the correct python from pyenv. I have 3.4.3 installed in pyenv with shared libraries (env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.4.3) and a virtualenv called "dev" with numpy installed and working.
My cmake command is as follow:
PREFIX_MAIN=`pyenv virtualenv-prefix`
PREFIX=`pyenv prefix`
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX="$PREFIX" \
-D PYTHON3_LIBRARY="$PREFIX_MAIN"/lib/libpython3.4m.so \
-D PYTHON3_INCLUDE_DIRS="$PREFIX_MAIN"/include/python3.4m \
-D PYTHON3_EXECUTABLE="$PREFIX"/bin/python3.4 \
-D PYTHON3_PACKAGES_PATH="$PREFIX"/lib/python3.4/site-packages/ \
-D PYTHON3_NUMPY_INCLUDE_DIRS="$PREFIX"/lib/python3.4/site-packages/numpy/core/include \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..
But cmake still does not want to find the Python 3 Libraires (see cmake output below):
-- Python 2:
-- Interpreter: /home/group/.pyenv/shims/python2.7 (ver 2.7.6)
--
-- Python 3:
-- Interpreter: /home/group/.pyenv/versions/dev/bin/python3.4 (ver 3.4.3)
-- Libraries: NO
-- numpy: /home/group/.pyenv/versions/dev/lib/python3.4/site-packages/numpy/core/include (ver 1.10.0.post2)
-- packages path: /home/group/.pyenv/versions/dev/lib/python3.4/site-packages
--
-- Python (for build): /home/group/.pyenv/shims/python2.7
Also it seems it wants to use "/home/group/.pyenv/shims/python2.7" for build. I don't think it is the problem.
Investigating the cmake ouput I found the following:
-- Found PythonInterp: /home/group/.pyenv/versions/dev/bin/python3.4 (found suitable version "3.4.3", minimum required is "3.4")
-- Could NOT find PythonLibs: Found unsuitable version "3.4.0", but required is exact version "3.4.3" (found /home/group/.pyenv/versions/3.4.3/lib/libpython3.4m.so)
It seems libpython3.4m.so is version 3.4.0.. although I explicitly installed 3.4.3...Could this be the problem? How can I get the proper PythonLibs?
I have very little experience with these things and I am frankly lost here...
EDIT: I have tried to compile with python version 3.4.0 on my pyenv (env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.4.0) and it worked using the cmake commands above. Either opencv wants explicitly 3.4.0 either I don't understand how the shared library installed for 3.4.3 are actually seen as 3.4.0...
EDIT: Same problem with python 2.7.10 under pyenv, you should use 2.7.6...
-- Found PythonInterp: /home/group/.pyenv/versions/cv2/bin/python2.7 (found suitable version "2.7.10", minimum required is "2.7")
-- Could NOT find PythonLibs: Found unsuitable version "2.7.6", but required is exact version "2.7.10" (found /home/group/.pyenv/versions/2.7.10/lib/libpython2.7.so)