现在可以直接安装opencv库
python2
sudo pip install opencv-python
python3
sudo pip3 install opencv-python
如果下载的很慢,或者下载超时,可以临时更换源,加入语句-i https://pypi.douban.com/simple
python2
sudo pip install opencv-python -i https://pypi.douban.com/simple
python3
sudo pip3 install opencv-python -i https://pypi.douban.com/simple
安装中如果出现如下问题,应该是缺少一些相关库
usr@Product-Name:~$ sudo pip3 install opencv-python -i https://pypi.douban.com/simple/
Collecting opencv-python
Downloading https://pypi.doubanio.com/packages/77/f5/49f034f8d109efcf9b7e98fbc051878b83b2f02a1c73f92bbd37f317288e/opencv-python-4.4.0.42.tar.gz (88.9MB)
100% |████████████████████████████████| 88.9MB 23kB/s
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.6/dist-packages (from opencv-python)
Installing collected packages: opencv-python
Running setup.py install for opencv-python ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-500j5ra5/opencv-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-akbhgedj-record/install-record.txt --single-version-externally-managed --compile:
/usr/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/skbuild/setuptools_wrap.py", line 560, in setup
cmkr = cmaker.CMaker(cmake_executable)
File "/usr/local/lib/python3.6/dist-packages/skbuild/cmaker.py", line 95, in __init__
self.cmake_version = get_cmake_version(self.cmake_executable)
File "/usr/local/lib/python3.6/dist-packages/skbuild/cmaker.py", line 82, in get_cmake_version
"Problem with the CMake installation, aborting build. CMake executable is %s" % cmake_executable)
Problem with the CMake installation, aborting build. CMake executable is cmake
----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-500j5ra5/opencv-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-akbhgedj-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-500j5ra5/opencv-python/
安装以下库,问题解决
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
在使用命令
sudo apt-get install libjaster-dev
出现:errorE: unable to locate libjasper-dev时,执行
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update