Install OpenCV on Ubuntu + python

Target

-[] Install OpenCV

environment

Install NumPy and OpenCV

$sudo apt-get install python-numpy
$sudo apt-get install python-opencv

OpenCV should have entered with this, but since it did not work due to an error from here, deal with it

Problem 1: The path does not pass

$python
>>> import cv2 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cv2

If you look closely, you will notice that the path to cv2.so is not set [/usr/lib/python2.7/dist-packages/]

>>> import sys
>>> print sys.path
['', '/usr/local/pyenv/versions/2.7.13/lib/python27.zip', '/usr/local/pyenv/versions/2.7.13/lib/python2.7', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/plat-linux2', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/lib-tk', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/lib-old', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/lib-dynload', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/site-packages']
>>> exit()
$sudo updatedb
$locate cv2
/usr/lib/python2.7/dist-packages/cv2.so
/usr/src/linux-headers-4.4.0-75/arch/arc/include/asm/entry-arcv2.h
/usr/src/linux-headers-4.4.0-75/arch/arc/include/asm/irqflags-arcv2.h
$

So add PATH and re-execute

>>> import sys
>>> sys.path.append("/usr/lib/python2.7/dist-packages")
>>> print sys.path
['', '/usr/local/pyenv/versions/2.7.13/lib/python27.zip', '/usr/local/pyenv/versions/2.7.13/lib/python2.7', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/plat-linux2', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/lib-tk', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/lib-old', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/lib-dynload', '/usr/local/pyenv/versions/2.7.13/lib/python2.7/site-packages', '/usr/lib/python2.7/dist-packages']
>>> import cv2
libdc1394 error: Failed to initialize libdc1394
>>> exit()

Then another error occurs

Problem 2: RAW device does not exist

When I checked the error content on Google, there was a comment from the person who dealt with it, so I will adopt it However, there is also "It is not a permanent solution.", So a different evacuation work may come out soon.

$ sudo ls /dev/raw1394
ls: cannot access /dev/raw1394: No such file or directory
$sudo ln /dev/null /dev/raw1394
$python
>>> import sys
>>> sys.path.append("/usr/lib/python2.7/dist-packages")
>>> import cv2
>>> cv2.__version__
'2.4.8'

Reference: OpenCV: libdc1394 error: Failed to initialize libdc1394

Permanent measures for problem 1

I added PATH with sys.path.append ("/usr/lib/python2.7/dist-packages"), but it is troublesome to add PATH every time because only the set session is valid. Create a definition file and change it so that PATH is set automatically The location is likely to be related to the package in the PATH displayed in sys.path Create a new custom.pth in /usr/local/pyenv/versions/2.7.13/lib/python2.7/site-packages

custom.pth


/usr/lib/python2.7/dist-packages/

Recommended Posts

Install OpenCV on Ubuntu + python
Install Python 3.3 on Ubuntu 12.04
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install OpenCV and Chainer on Ubuntu
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
OpenCV3 & Python3 environment construction on Ubuntu
Install TensorFlow on Ubuntu
Install python on WSL
Install Python on Pidora.
Install Scrapy on python3
Build Python3 and OpenCV environment on Ubuntu 18.04
Install Python on Mac
Install Python 3 on Mac
Install PySide2 on Ubuntu
Install Python3.4 on CentOS 6.6
Install JModelica on Ubuntu
Created Ubuntu, Python, OpenCV environment on Docker
Install python on windows
Install Python 2.7.3 on CentOS 5.4
build Python on Ubuntu
Install Python 3.4 on Mac
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Install Theano on Ubuntu 12.04
Install angr on Ubuntu 18.04
Install pip / pip3 on Ubuntu
Install Python 3.6 on Docker
How to install OpenCV on Jetson Nano Python
Install python package in personal environment on Ubuntu
[Procedure memo] Install Python3 + OpenSSL locally on Ubuntu
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
[Python] How to install OpenCV on Anaconda [Windows]
Install MongoDB on Ubuntu 16.04 and operate via python
Set up Python 3.4 on Ubuntu
Install Python 3.8 on RHEL 8 (AppStream)
Use matplotlib on Ubuntu 12 & Python
Install watchdog on Windows + Python 3.3
Install pygame on python3.4 on mac
Install Python 3.8 on CentOS 7 (SCL)
Put Python 3.x on Ubuntu
Install GoLand IDE on Ubuntu
wsl Install PostgreSQL on Ubuntu 18.04
Python --Install MySQLDB on EC2
Introducing TensorFlow on Ubuntu + Python 2.7
[ROS] Install ROS (melodic) on Ubuntu (18.04)
Install Caffe on Ubuntu 14.04 (GPU)
Install Python 3.8 on CentOS 8 (AppStream)
Install Docker on WSL Ubuntu 18.04
[Python] [Chainer] [Windows] Install Chainer on Windows
Install OpenCV4 on Raspberry Pi 3
(CMake) Gently install official OpenCV on WSL (C / C ++, Python2, Python3)
install python
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Install Bash on Ubuntu on Windows, Ruby, Python, Jupyter, etc.
Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04
Install Python Pillow on Amazon Linux
Python 3.4 pyvenv fails on Ubuntu 14.04 LTS
Install Caffe on Ubuntu 14.04 (CPU mode)
Prepare Python development environment on Ubuntu