Raspbian命令行安装指定版本picamera2
1. 源由
上面的问题,主要还是树莓派上查找摄像头设备出现异常的问题。目前基本已经定位到是picamera2
的兼容性问题。
因此,我们需要了解如何卸载、安装、安装指定版本的picamera2
,进而再指定OS下安装特定版本,从而解决上述问题。
2. 卸载、升级、安装
注:pip 可以替换为pip3,具体看python当前环境,本机默认是python3。
2.1 查看
$ pip list | grep picamera2
2.2 卸载
$ pip uninstall picamera2
2.3 升级
$ python -m pip install --upgrade pip
2.4 安装
$ pip install picamera2
安装指定版本:
$ pip install picamera2==<版本号>
3. OS指定版本安装
$ nano ./install_picamera2.sh
$ chmod +x install_picamera2.sh
$ cat ./install_picamera2.sh
#!/bin/bash
# Function to detect the OS version
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
VERSION=$VERSION_ID
else
echo "OS detection not supported. Exiting."
exit 1
fi
}
# Function to install picamera2 for Bullseye
install_bullseye() {
echo "Installing picamera2=0.3.12 for Bullseye..."
pip install picamera2==0.3.12
}
# Function to install picamera2 for Bookworm
install_bookworm() {
echo "Installing picamera2 for Bookworm..."
pip install picamera2
}
# Main script
detect_os
echo "Detected OS: $OS"
echo "Detected Version: $VERSION"
# picamera2 needs libcap
sudo apt-get install libcap-dev
if [[ $OS == "Debian GNU/Linux" || $OS == "Raspbian GNU/Linux" ]]; then
case $VERSION in
"11")
install_bullseye
;;
"12")
install_bookworm
;;
*)
echo "Unsupported Debian/Raspbian version: $VERSION. Exiting."
exit 1
;;
esac
else
echo "Unsupported OS: $OS. Exiting."
exit 1
fi
echo "Installation complete."
4. 补充 - 安装异常
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
You need to install libcap development headers to build this module
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
需要提前安装 libcap 开发头文件:
$ sudo apt-get install libcap-dev