You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派4 Ubuntu 23.04环境下PvRecorder在systemd服务中初始化失败的问题求助

树莓派4 Ubuntu 23.04环境下PvRecorder在systemd服务中初始化失败的问题求助

我在树莓派4(Ubuntu 23.04)上用Python脚本运行PvRecorder,单独运行脚本完全正常,但通过systemd服务启动时就会报错,想请教大家这是为什么,以及该怎么解决。

我的Python脚本(test.py)

#! /home/kuri/Kuri/bin/python

from pvrecorder import PvRecorder

recorder = PvRecorder(device_index=-1, frame_length=512)

我是用虚拟环境来运行这个脚本的,直接执行/home/kuri/Kuri/bin/python /home/kuri/Kuri/test.py时完全没问题。

我的systemd服务配置(chatbot.service)

[Unit]
Description=Chatbot service
After=network.target

[Service]
Type=simple
User=root
ExecStart=/home/kuri/Kuri/bin/python /home/kuri/Kuri/test.py
WorkingDirectory=/home/kuri/Kuri

[Install]
WantedBy=multi-user.target

服务启动时的错误日志

chatbot.service - Chatbot Service
Loaded: loaded (/lib/systemd/system/chatbot.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Sun 2023-05-28 15:19:37 EDT; 51min ago
Duration: 716ms
Process: 872 ExecStart=/home/kuri/Kuri/bin/python /home/kuri/Kuri/test.py (code=exited, status=1/FAILURE)
Main PID: 872 (code=exited, status=1/FAILURE)
CPU: 288ms

May 28 15:19:37 kuri python[872]: ALSA lib pcm_dsnoop.c:566:(snd_pcm_dsnoop_open) unable to open slave
May 28 15:19:37 kuri python[872]: Traceback (most recent call last):
May 28 15:19:37 kuri python[872]:   File "/home/kuri/Kuri/test.py", line 4, in <module>
May 28 15:19:37 kuri python[872]:   recorder = PvRecorder(device_index=-1, frame_length=512)
May 28 15:19:37 kuri python[872]:               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 28 15:19:37 kuri python[872]:   File "/home/kuri/Kuri/lib/python3.11/site-packages/pvrecorder/pvrecorder.py", line 81 in __init__
May 28 15:19:37 kuri python[872]:   raise self._PVRECORDER_STATUS_TO_EXCEPTION[status]("Failed to initialize pv_recorder.")
May 28 15:19:37 kuri python[872]: RuntimeError: Failed to initialize pv_recorder.
May 28 15:19:37 kuri systemd[1]: chatbot.service: Main process exited, code=exited, status=1/FAILURE
May 28 15:19:37 kuri systemd[1]: chatbot.service: Failed with result 'exit-code'.

想请教大家:为什么只有通过systemd服务运行时才会抛出这些错误?我该怎么解决这个问题?

备注:内容来源于stack exchange,提问作者LordOfFrogs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 14:05:30