Fangyijie Wang

Issues found during OpenCV Python installation

In last article, I’ve shared my story about how to install OpenCV 3.1.0 associated with Python 3.5 on Ubuntu system. Continue with it, I’m going to share some issues I found during installation of OpenCV and Python.

Details of my local environment:

  • ubuntu 16.04 LTS
  • Python 3.5.2
  • OpenCV 3.1.0

Anaconda installed before virtual environment setup

As my last article mentions, it’s highly recommended to create virtual environment to install and use Python. However on my local machine, I installed Ananconda which includes many useful Python libs. If you are familiar with Anaconda, it is a very handy software for Python development.

As I already have Anaconda (Python 3.5) on my machine, When I want to install OpenCV, I found and installed a OpenCV library associated with Anaconda. You could follow installation instructions on my last article, but skip the part of creating virtual environment. Please note you will need to change CMake commands like below:

1
2
3
4
5
6
7
8
9
10
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D PYTHON_EXECUTABLE=~/anaconda3/envs/py35/bin \
-D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so \
-D PYTHON_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython3.5m.so \
-D PYTHON3_NUMPY_INCLUDE_DIRS=~/anaconda3/envs/py35/site-packages \
-D BUILD_EXAMPLES=ON ..

You need to point PYTHON_EXECUTABLE and PYTHON3_NUMPY_INCLUDE_DIRS to location of Python 3.5 and Numpy respectively. I believe they are all in Anaconda folder. Then you can build OpenCV with CMake. I guess the output would be like below screenshot:
cmake anaconda py35

In my case, the output says OpenCV is associated with Python 3.5 (from Anaconda). But when I try to import cv2 in Python environment, below error shown up:
cmake error

I googled lots of docs related with this error, but no luck… No solution is working for me unless I deleted Anaconda completely, create virtual environment and install everything from scratch.

Permission issue

Also, I found another permission issue maybe caused by Anaconda on my local machine. The error is shown up during CMake build:
permission error

After I did lots of research on this issue, again my final stupid solution is deleteing Anaconda and start everything from scratch.

Currently I only have above two issues when I was installing OpenCV and Python on Ubuntu. If you know the better solutions to solve them, please let me know ! Thanks a mil.