Problems when Installing opencv3.0 in Ubuntu14.04LTS, Python3.4 with vertualenv

For the most parts, you should follow the advices in

http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/,

but I encounterd some problems. For example, I don't have site-packages (I have one only in my virtual environment). I show you how I addressed them in this article.

When CMake Cannot Find Python Library 

Add the line
set(Python_ADDITIONAL_VERSIONS 3.4)
in CMakeLists.txt in opencv. You may edit it with vim:
$sudo vim ~/opencv/CMakeLists.txt
. Then, CMakeLists.txt should be like this:

# ----------------------------------------------------------------------------
#  Root CMake file for OpenCV
#
#    From the off-tree build directory, invoke:
#      $ cmake <PATH_TO_OPENCV_ROOT>
#
# ----------------------------------------------------------------------------

set(Python_ADDITIONAL_VERSIONS 3.4)
include(cmake/OpenCVMinDepVersions.cmake)

if(CMAKE_GENERATOR MATCHES Xcode AND XCODE_VERSION VERSION_GREATER 4.3)
  cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
Then, try cmake again.
 You can check in the cmake log if Python3 library was successfully detected.

Just adding  following satements was not effective.
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export PYTHON_INCLUDE_DIRS=/usr/include/python3.4m
export PYTHON_LIBRARIES=/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu/libpython3.4m.so
They might be needed but not enough just by them. I'm not sure if you must add them in CMakeLists.txt.

See also: https://github.com/SFTtech/openage/issues/12

When Opencv Installed but Can't Find It.

Try locating it in python console. Don't do this in the virtual environment as you still cannot import opencv in your virtual environment.
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__file__)
/usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so
Then, you can make sym-link to import opencv in the virtual environment.
cd /usr/bin/myenv/lib/python3.4/site-packages
sudo ln -s /usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so
Finally, check out if opencv can be imported in your virtual environment
(myenv)watanabe@watanabe-HP-Pavilion-dm1-Notebook-PC:/usr/bin/myenv/lib/python3.4/site-packages$ python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.0.0'
>>> cv2.__file__
'/usr/bin/myenv/lib/python3.4/site-packages/cv2.cpython-34m.so'

Felicitations ! :D

コメント

人気の投稿