Installing OpenCV 3.4.1 using Python 3 on Raspbian Stretch
UPDATED OCT 2020
See this link for a much better procedure:
This is left for archiving purposes:
As usual, I will keep this short and sweet.
- Make sure you have Raspbian Stretch installed and upadted. Alsi rpi-update!
- edit /etc/php.conf and add
-
[global] extra-index-url=https://www.piwheels.org/simple
-
- Download OpenCV source from opencv.org and compile it
- unzip
- cd opencv-x.x.x
- mkdir build
- cd build
- CMake or cmake-gui
- make
- make install
- Create a virtual environment
-
$ sudo apt install virtualenv python3-virtualenv -y $ virtualenv -p /usr/bin/python3 testpip $ source testpip/bin/activate (testpip) $ pip install numpy ... (testpip) $ deactivate $ rm -fr testpip/
-
- Install packages from piwheels into that environment
-
pip install numpy
-
pip install opencv-python
-
pip install opencv-contrib-python
-
- Verify installation
-
$ python Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> import numpy
Should give no errors
-
If you get this error when installing opencv-python
alpha@pi2:~/PYTHON/demo $ pip install opencv-python Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting opencv-python Could not find a version that satisfies the requirement opencv-python (from versions: ) No matching distribution found for opencv-python
You should make sure that you are in the virtual environment created above, easy to forget if you switch terminals!