How to install OpenCV 3.1 for Python 3.5 On Ubuntu 16.04 LTS?
I found this.
OpenCV on wheels.
Unofficial OpenCV packages for Python.
Installation was painless for Ubuntu 16.04:
pip3 install opencv-python
Check the installation:
python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'
python3-opencv can be installed from the Universe repository in Ubuntu 17.10 and later. Open the terminal and type:
sudo apt install python3-opencv
Upgrade your OS to 18.04 if you are using Ubuntu 14.04 or Ubuntu 16.04. If Ubuntu 16.04 is installed in WSL sudo do-release-upgrade
will upgrade it to 18.04.
I have OpenCV version 3.1 on Ubuntu 16.04 LTS to work with Python 3.5.1. At the latest version it's fixed, try:
http://cyaninfinite.com/tutorials/installing-opencv-in-ubuntu-for-python-3/
But I didn't download dev python and OpenCV, I took directly from github:
EDIT:
Here are the instructions I tested successfully and mentioned in the link above:
- Update the repository:
sudo apt-get update
Download the required packages to compile OpenCV:
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
- Install the developer packages for Python3.5:
sudo apt-get install python3.5-dev
- Copy the dev files:
python3.5-config --includes
The output should be similar to:-I/usr/include/python3.5m -I/usr/include/x86_64-linux-gnu/python3.5m
. The first part of the output is the expected location & the second part shows the current location of the config file. To solve this problem, we’ll copy the file from the current location to the expected location:sudo cp /usr/include/x86_64-linux-gnu/python3.5m/pyconfig.h /usr/include/python3.5m/
- Create a temporary directory, move into it and run:
git clone https://github.com/Itseez/opencv.git
. This will download OpenCV 3. Then rename the folderopencv
toopencv-3
Create a
build
directory, move to it and run:cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ../opencv-3
- After the process is finished, run
make
and thensudo make install
. - Enjoy.