先安装一些依赖项(笔者由于什么都不懂到处看所以装了很多很多乱七八糟的...有空整理一下)
书上是写了如下几项
sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-100
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
除此之外可能还有
//安装pip工具
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo apt install python3-pip
//安装虚拟环境
$ sudo apt-get install python3-venv
常规正常pip下载是直接sudo pip install opencv-contrib-python
然而因为系统的更新这种方式会报错在官网上的解释是
在旧版本的 Raspberry Pi OS 中,您可以使用 将库直接安装到 Python 的系统版本中。由于 Raspberry Pi OS Bookworm 导致用户无法将库直接安装到 Python 的系统版本中。从 Raspberry Pi OS Bookworm 开始,通过 (Adobe) 安装的软件包必须安装到 Python 虚拟环境 中。虚拟环境是一个容器,您可以在其中安全地安装第三方模块,这样它们就不会干扰您的系统 Python。
所以先创建一个全局虚拟环境
使用以下命令在当前用户主目录的隐藏文件夹中创建虚拟环境:
$ python -m venv ~/.env
运行以下命令以开始使用虚拟环境:
$ source ~/.env/bin/activate
然后应该会看到类似于以下内容的提示:
(.env)$
之后用pip安装想安装的库(注意不需要sudo了!!!)
pip install opencv-contrib-python
安装完成可以用如下命令检测
$ workon py3cv3
$ python
>>> import cv2
>>> cv2.__version__
输出opencv版本为成功安装
另外一些碎碎念((实为走过的弯弯弯弯弯弯弯弯路((((
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
For more information visit http://rptl.io/venv
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
整一段话只有网址有用(
try apt install python3-xyz 纯sb 安装不上
(.env) vita@raspberrypi:~ $ apt install python3-xyz
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
vita@raspberrypi:~ $ sudo apt install python3-xyz
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python3-xyz
但很神奇的是用网上的查找,显示有这个东西...
vita@raspberrypi:~ $ apt-cache search python3-xyz
python3-xyzservices - Source of XYZ tiles providers
然后笔者又根据网上建议说是在 sudo nano /etc/apt/sources.list里面添加网址
http://archive.ubuntu.com/ubuntu focal InRelease
http://archive.ubuntu.com/ubuntu focal-updates InRelease
http://archive.ubuntu.com/ubuntu focal-security InRelease
关于文档修改...也提一嘴...因为笔者什么都不会,感觉保存好麻烦
具体操作:ctrl+O保存
显示 "File Name to Write: /etc/apt/..."
直接enter(默认原地保存)
ctrl+X退出
之后sudo apt-get update
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian-security bookworm-security InRelease
Hit:3 http://archive.raspberrypi.com/debian bookworm InRelease
Hit:4 http://deb.debian.org/debian bookworm-updates InRelease
Get:5 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-updates InRelease [128 kB]
Err:5 http://archive.ubuntu.com/ubuntu focal InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 NO_PUBKEY 871920D1991BC93C
Err:6 http://archive.ubuntu.com/ubuntu focal-updates InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 NO_PUBKEY 871920D1991BC93C
Get:7 http://archive.ubuntu.com/ubuntu focal-security InRelease [128 kB]
Err:7 http://archive.ubuntu.com/ubuntu focal-security InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 NO_PUBKEY 871920D1991BC93C
报错((似乎是密钥的问题...
然后常规的apt-key修改密钥方法也由于linux系统更新去掉了...
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 871920D1991BC93C
所以这个不行...至于怎么修改笔者至今没搞懂((不过目前来看也不需要搞懂了
由于笔者只是想用树莓派做项目...所以并没有过多探究背后原因的想法,在此只是先存个档
另外似乎进行什么操作都要update来两下
$ sudo apt-get update
$ sudo apt upgrade