在树莓派上安装opencv-python-3.1.0
在树莓派上安装opencv-python3.1.0的坎坷之路
由于要做人脸识别,在运行源文件的时候出现错误:
Traceback (most recent call last):
File "Face.py", line 4, in <module>
recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'face'
于是我以为是我的版本问题,我就把函数名改成cv2.createLBPHFaceRecognizer()试了一下,还是不行。问了度娘开始按照经典解决方法操作:卸载opencv-python文件再重新安装,指令如下:
pip uninstall opencv-contrib-python
pip uninstall opencv-python
pip install opencv-python
pip install opencv-contrib-python
# 直接用pip下载比较慢,要记得用豆瓣代理来下载。
pip install --index-url https://pypi.douban.com/simple 包名
然而,我在树莓派上这样操作的时候出现了错误提示说我并没有下载这两个包!orz
~$ pip uninstall opencv-contrib-python
Cannot uninstall requirement opencv-contrib-python, not installed
~$ pip uninstall opencv-python
Cannot uninstall requirement opencv-python, not installed
好的,没有我就直接下载了,当我这样做的时候,又出错了
Repp@Repp:~$ pip install --index-url https://pypi.douban.com/simple opencv-python
Collecting opencv-python
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xffffb75daf10>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xffffb75780d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xffffb7578250>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xffffb75783d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xffffb7578550>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/opencv-python/
Could not find a version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python
于是之后我又去问度娘,找到了一种第三方安装的方法,即事先在这里下载好安装包
由于我树莓派上python的版本为3.6.9,我就下了3.1.0的版本,拷到了树莓派的Downloads文件中。正当我开开心心地觉得我即将完成安装时
pip install D:\Downloads\opencv_python-3.1.0-cp34-cp34m-win_amd64.whl
又!出现了错误:
opencv_python-3.1.0--cp34-cp34m-win_amd64.whl is not a supported wheel on this platform
我再去问度娘,得到回答说:可能安装的不是对应python版本的库。我去查了一下当前python版本支持的文件是哪些,查看方法为:
Repp@Repp:~$ python3
>>> import pip
>>> print(pip.pep425tags.get_supported())
>>> [('cp36', 'cp36m', 'linux_aarch64'), ('cp36', 'abi3', 'linux_aarch64'), ('cp36', 'none', 'linux_aarch64'), ('cp35', 'abi3', 'linux_aarch64'), ('cp34', 'abi3', 'linux_aarch64'), ('cp33', 'abi3', 'linux_aarch64'), ('cp32', 'abi3', 'linux_aarch64'), ('py3', 'none', 'linux_aarch64'), ('cp36', 'none', 'any'), ('cp3', 'none', 'any'), ('py36', 'none', 'any'), ('py3', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]
可以获取到pip支持的文件名还有版本,我这里如下:
后面把当地的文件名改成opencv_python-3.1.0-cp36-cp36m-linux_aarch64.whl
开始下载:
Repp@Repp:~/Desktop$ pip3 install /home/wheeltec/Downloads/opencv_python-3.1.0-cp36-cp36m-linux_aarch64.whl
Processing /home/wheeltec/Downloads/opencv_python-3.1.0-cp36-cp36m-linux_aarch64.whl
Installing collected packages: opencv-python
Successfully installed opencv-python-3.1.0
最后安装成功,开始搞人脸识别。我太难了><