1、给树莓派换源
此处使用的系统是debian10(buster)
,其他系统版本的官方系统换源可以借鉴清华大学镜像站
(1)、编辑 /etc/apt/sources.list
文件,删除原文件所有内容,用以下内容取代:
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi
(2)、编辑 /etc/apt/sources.list.d/raspi.list
文件,删除原文件所有内容,用以下内容取代:
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
安装后使用以下命令更新源:
sudo apt update
2、安装pip并更换pip源
(1)、安装pip3
sudo apt install python3-pip
(2)、更新pip并换源
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
(3)、修改默认python版本
可以把更改默认python
,默认的一般为python2
,使用以下命令可以更改默认python
,当输入python
时就会默认打开python3
,而不是原本的python2
:
update-alternatives --install /usr/bin/python python /usr/bin/python3 150
如果想改回默认的python2
,可以使用以下命令:
update-alternatives --install /usr/bin/python python /usr/bin/python2 100
3、安装opencv依赖
sudo apt-get install libhdf5-dev -y
sudo apt-get install libatlas-base-dev -y
sudo apt-get install libjasper-dev -y
sudo apt-get install libqt4-test -y
sudo apt-get install libqtgui4 -y
sudo apt-get install libhdf5-serial-dev -y
sudo apt install libqtgui4 -y
sudo apt install libqt4-test -y
4、安装opencv和opencv-contrib
此处安装opencv
使用的是清华源,但是安装opencv-contrib
时使用的是豆瓣源,豆瓣源有编译好的opencv-contrib
的轮子,其他源需要编译,花费的时间较短
pip3 install opencv-python #使用默认源安装opencv-python
pip3 install -i http://pypi.douban.com/simple/ opencv-contrib-python #使用豆瓣源安装opencv-contrib-python
PS:只安装opencv
不安装opencv-contrib
将会导致cv2
不可用,即在python中使用import cv2
会报错,所以得安装opencv-contrib
,依赖也是必须的,不然也会报错。此安装方法在树莓派官方系统raspbian(debian版本为debian10(buster))
安装一切正常,其他版本系统未测试。