|
|
|
|
更换为国内源可以提高软件包下载速度。常用的国内源有中科大、清华大学、阿里云等。下面是将 Debian Bookworm 的源替换为国内源的步骤:
|
|
|
|
|
|
|
|
|
|
### 步骤:
|
|
|
|
|
|
|
|
|
|
1. **备份当前源列表(可选):**
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. **编辑 `sources.list` 文件:**
|
|
|
|
|
|
|
|
|
|
使用你喜欢的文本编辑器(例如 `nano`、`vim` 或 `gedit`)编辑 `/etc/apt/sources.list` 文件:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo nano /etc/apt/sources.list
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
3. **更新源列表内容:**
|
|
|
|
|
|
|
|
|
|
下面是使用清华大学的镜像源作为示例,可以将其内容粘贴到 `sources.list` 文件中:
|
|
|
|
|
|
|
|
|
|
```plaintext
|
|
|
|
|
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
|
|
|
|
|
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
|
|
|
|
|
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
其他可用的国内源示例:
|
|
|
|
|
|
|
|
|
|
**中科大镜像源:**
|
|
|
|
|
|
|
|
|
|
```plaintext
|
|
|
|
|
deb http://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
|
|
|
|
|
deb http://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
|
|
|
|
|
deb http://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src http://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src http://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src http://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**阿里云镜像源:**
|
|
|
|
|
|
|
|
|
|
```plaintext
|
|
|
|
|
deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware
|
|
|
|
|
deb http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware
|
|
|
|
|
deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware
|
|
|
|
|
#deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
4. **保存并退出编辑器:**
|
|
|
|
|
|
|
|
|
|
- 如果使用 `nano`,按 `Ctrl+O` 保存文件,然后按 `Ctrl+X` 退出编辑器。
|
|
|
|
|
|
|
|
|
|
5. **更新软件包列表:**
|
|
|
|
|
|
|
|
|
|
运行以下命令来更新软件包列表:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo apt-get update
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 验证更新
|
|
|
|
|
|
|
|
|
|
在运行 `sudo apt-get update` 后,你应该看到类似如下的输出,表示成功从新的软件源获取了软件包列表:
|
|
|
|
|
|
|
|
|
|
```plaintext
|
|
|
|
|
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm InRelease
|
|
|
|
|
Hit:2 https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security InRelease
|
|
|
|
|
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates InRelease
|
|
|
|
|
Reading package lists... Done
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 安装和升级软件包
|
|
|
|
|
|
|
|
|
|
如果需要升级所有已安装的软件包,可以运行:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo apt-get upgrade
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
或者安装特定软件包:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo apt-get install <package-name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
通过这些步骤,你可以使用国内镜像源加快软件包的下载速度。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### PYTHON 虚拟环境
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
您遇到了一个与环境管理相关的错误信息,这是因为您的系统被配置为限制在系统范围内安装 Python 包。为了避免破坏系统配置,建议使用虚拟环境来安装和管理 Python 包。以下是具体步骤:
|
|
|
|
|
|
|
|
|
|
1. **创建虚拟环境**:
|
|
|
|
|
|
|
|
|
|
在您的项目目录下创建一个虚拟环境:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
python3 -m venv venv
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. **激活虚拟环境**:
|
|
|
|
|
|
|
|
|
|
激活刚刚创建的虚拟环境:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
source venv/bin/activate
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
激活后,您会看到命令提示符前面多了 `(venv)`,表示您已经在虚拟环境中。
|
|
|
|
|
|
|
|
|
|
3. **安装 paho-mqtt**:
|
|
|
|
|
|
|
|
|
|
在激活的虚拟环境中,使用 `pip` 安装 `paho-mqtt` 库:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
pip install paho-mqtt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
4. **验证安装**:
|
|
|
|
|
|
|
|
|
|
您可以通过运行一个简单的 Python 脚本来验证是否成功安装了 `paho-mqtt`:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import paho.mqtt.client as mqtt
|
|
|
|
|
|
|
|
|
|
def on_connect(client, userdata, flags, rc):
|
|
|
|
|
print("Connected with result code " + str(rc))
|
|
|
|
|
|
|
|
|
|
client = mqtt.Client()
|
|
|
|
|
client.on_connect = on_connect
|
|
|
|
|
|
|
|
|
|
client.connect("mqtt.eclipse.org", 1883, 60)
|
|
|
|
|
|
|
|
|
|
client.loop_forever()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
将以上代码保存为一个 Python 文件(例如 `mqtt_test.py`),然后运行它:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
python mqtt_test.py
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果成功连接到 MQTT 服务器,会看到输出类似于:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
Connected with result code 0
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
这样,您就可以在虚拟环境中安装和使用 `paho-mqtt` 库,而不会影响系统的其他部分。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### redis 安装
|
|
|
|
|
|
|
|
|
|
在您的 Raspberry Pi 上安装 Redis,可以使用以下步骤:
|
|
|
|
|
|
|
|
|
|
1. **更新系统包列表**:
|
|
|
|
|
|
|
|
|
|
首先,更新您的系统包列表:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
sudo apt-get update
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. **安装 Redis**:
|
|
|
|
|
|
|
|
|
|
使用 `apt-get` 安装 Redis:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
sudo apt-get install redis-server
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
3. **验证安装**:
|
|
|
|
|
|
|
|
|
|
安装完成后,您可以通过以下命令来检查 Redis 服务是否正在运行:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
sudo systemctl status redis
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果 Redis 正在运行,您会看到类似以下的输出:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
● redis-server.service - Advanced key-value store
|
|
|
|
|
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
|
|
|
|
|
Active: active (running) since [date and time]
|
|
|
|
|
Docs: http://redis.io/documentation,
|
|
|
|
|
man:redis-server(1)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
4. **测试 Redis**:
|
|
|
|
|
|
|
|
|
|
您可以通过 `redis-cli` 命令行工具来测试 Redis:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
redis-cli
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
在 Redis 命令行中,输入以下命令进行测试:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
set test "Hello, Redis!"
|
|
|
|
|
get test
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果安装成功,您会看到:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
"Hello, Redis!"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
5. **设置 Redis 开机自启动**:
|
|
|
|
|
|
|
|
|
|
Redis 通常默认设置为开机自启动,如果没有,可以使用以下命令设置:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
sudo systemctl enable redis
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
这将确保 Redis 在系统启动时自动运行。
|
|
|
|
|
|
|
|
|
|
通过这些步骤,您应该能够在您的 Raspberry Pi 上成功安装并运行 Redis。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
拍照时间较长可能由以下几个原因造成:
|
|
|
|
|
|
|
|
|
|
1. **系统性能限制**:树莓派的性能相对于现代桌面计算机较弱,处理图像可能需要更多时间。
|
|
|
|
|
|
|
|
|
|
2. **图像分辨率设置较高**:较高的分辨率会增加处理时间,尤其是在较慢的存储设备上。
|
|
|
|
|
|
|
|
|
|
3. **存储设备性能**:使用较慢的存储卡(例如低速的SD卡)会影响写入速度。
|
|
|
|
|
|
|
|
|
|
4. **摄像头驱动和固件问题**:摄像头的驱动和固件可能不完全优化。
|
|
|
|
|
|
|
|
|
|
5. **软件设置**:某些软件设置可能会导致额外的处理时间。
|
|
|
|
|
|
|
|
|
|
### 优化拍照时间的方法
|
|
|
|
|
|
|
|
|
|
1. **降低图像分辨率**:
|
|
|
|
|
- 拍照时使用较低的分辨率可以加快处理速度。可以在命令中指定分辨率:
|
|
|
|
|
```bash
|
|
|
|
|
libcamera-still -o image.jpg -r 640x480
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. **使用更快的存储设备**:
|
|
|
|
|
- 确保使用高速的SD卡,建议使用Class 10或更高的SD卡。
|
|
|
|
|
|
|
|
|
|
3. **优化系统性能**:
|
|
|
|
|
- 关闭不必要的后台服务和应用程序,释放更多的系统资源给拍照进程。
|
|
|
|
|
|
|
|
|
|
4. **检查和更新驱动**:
|
|
|
|
|
- 确保使用最新版本的驱动和固件。您可以运行以下命令更新系统:
|
|
|
|
|
```bash
|
|
|
|
|
sudo apt-get update
|
|
|
|
|
sudo apt-get upgrade
|
|
|
|
|
sudo rpi-update
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
5. **减少预览时间**:
|
|
|
|
|
- 拍照前的预览时间可以通过调整参数减少。例如,使用 `--timeout` 参数设置拍照前的延迟时间(单位为毫秒):
|
|
|
|
|
```bash
|
|
|
|
|
libcamera-still -o image.jpg --timeout 1000
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
6. **避免使用过多处理选项**:
|
|
|
|
|
- 拍照时避免使用过多的处理选项,例如多次采样、降噪等。
|
|
|
|
|
|
|
|
|
|
### 示例命令
|
|
|
|
|
|
|
|
|
|
降低分辨率和减少预览时间的拍照命令:
|
|
|
|
|
```bash
|
|
|
|
|
libcamera-still -o image.jpg -r 640x480 --timeout 1000
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
通过这些方法,您应该能显著减少拍照的时间。如果问题仍然存在,建议查看摄像头模块的文档,或在树莓派的支持论坛上寻求更多帮助。
|