System Dependencies Installation
Overview
This document provides a complete dependency installation guide for the py-xiaozhi project.
Tech Stack:
- Python >= 3.10
- GUI: PySide6
- Package Management: uv (recommended) / pip
System Dependencies
Windows
# Install with Scoop (recommended)
scoop install ffmpeg
# Or with winget
winget install FFmpegOpus Codec: The project already includes opus.dll, so no additional installation is usually needed. If you encounter issues, copy /libs/windows/opus.dll to the application directory or C:\Windows\System32.
macOS
# Homebrew installation
brew install portaudio opus ffmpeg
# Xcode Command Line Tools
xcode-select --installLinux (Debian/Ubuntu)
Compatible with Ubuntu 20.04 / 22.04 / 24.04 / 25.04 and Raspberry Pi OS
Choose the appropriate installation command based on your system version. Different versions have different ALSA package names and default audio servers.
Check system version:
lsb_release -d # or cat /etc/os-releaseUbuntu 22.04 (Recommended)
Default audio server: PipeWire (compatible with PulseAudio)
sudo apt-get update
sudo apt-get install -y \
portaudio19-dev libportaudio2 \
ffmpeg libopus0 libopus-dev \
libasound2-dev \
pulseaudio-utils \
libxcb-xinerama0 libxkbcommon-x11-0 \
build-essential python3-venv python3-pipUbuntu 24.04 / 25.04
Default audio server: PipeWire. The ALSA dev package has been renamed to libasound-dev (the old name libasound2-dev still works).
sudo apt-get update
sudo apt-get install -y \
portaudio19-dev libportaudio2 \
ffmpeg libopus0 libopus-dev \
libasound-dev \
pulseaudio-utils \
libxcb-xinerama0 libxkbcommon-x11-0 \
build-essential python3-venv python3-pipUbuntu 20.04
Note: Ubuntu 20.04 has Python 3.8 by default. You need to install Python 3.10+ first.
# 1. Install Python 3.10+
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install -y python3.10 python3.10-venv python3.10-dev
# 2. Install audio dependencies (default audio server: PulseAudio)
sudo apt-get install -y \
portaudio19-dev libportaudio2 \
ffmpeg libopus0 libopus-dev \
libasound2-dev \
pulseaudio-utils \
build-essentialRaspberry Pi OS (Bookworm / Debian 12)
The desktop edition has PipeWire pre-installed. The Lite edition requires manual installation of an audio server.
sudo apt-get update
# Desktop edition: PipeWire is pre-installed, only need dev dependencies
sudo apt-get install -y \
portaudio19-dev libportaudio2 \
ffmpeg libopus0 libopus-dev \
libasound-dev \
pulseaudio-utils \
build-essential python3-venv python3-pip
# Lite edition (no desktop): additionally install audio server:
# sudo apt-get install -y pipewire pipewire-pulse wireplumberFor Raspberry Pi, it's recommended to use a USB sound card. The built-in 3.5mm audio jack has poor quality and high latency.
Audio Permissions
sudo usermod -a -G audio $USER
# Takes effect after re-loginAudio Verification
# Check audio server
pactl info | grep "Server Name"
# Expected output:
# PulseAudio → "Server Name: pulseaudio"
# PipeWire → "Server Name: PulseAudio (on PipeWire x.x.x)"
# Check sound card devices
aplay -l # List output devices
arecord -l # List input devices
# Check PortAudio
python3 -c "import sounddevice; print(sounddevice.query_devices())"Important: Do NOT install the
pulseaudiodaemon package on PipeWire systems (Ubuntu 22.04+), as this will conflict with PipeWire. Only installpulseaudio-utils(which provides thepactlcommand).
Python Environment Setup
Method 1: uv (Recommended)
uv is a modern Python package manager that is fast and manages virtual environments automatically.
Install uv:
# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Install project dependencies:
uv syncRun the project:
uv run python main.pyMethod 2: pip + venv
# Create virtual environment
python3 -m venv .venv
# Activate virtual environment
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txtMethod 3: Conda (Optional)
Only use when special C++ dependencies (e.g., CUDA/MKL) are needed
# Create environment
conda create -n py-xiaozhi python=3.10 -y
conda activate py-xiaozhi
# Install dependencies
pip install -r requirements.txtVerify Installation
# Using uv
uv run python -c "from PySide6.QtCore import qVersion; print('PySide6:', qVersion())"
uv run python -c "import sounddevice; print('SoundDevice OK')"
uv run python -c "import opuslib; print('Opus OK')"
uv run python -c "import sherpa_onnx; print('sherpa-onnx OK')"
# Using pip/venv
python -c "from PySide6.QtCore import qVersion; print('PySide6:', qVersion())"
python -c "import sounddevice; print('SoundDevice OK')"Troubleshooting
SoundDevice Installation Failure
# Ubuntu 20.04 / 22.04
sudo apt-get install -y portaudio19-dev libasound2-dev libportaudio2
# Ubuntu 24.04+
sudo apt-get install -y portaudio19-dev libasound-dev libportaudio2
# macOS
brew install portaudioAudio Device Not Found (Linux)
Common on Raspberry Pi or service auto-start scenarios. PortAudio initializes before the audio service is ready, resulting in an empty device list.
# 1. Confirm audio service is running
pactl info
# 2. If pactl reports an error, check the audio service
systemctl --user status pipewire pipewire-pulse # PipeWire system
systemctl --user status pulseaudio # PulseAudio system
# 3. If aplay -l shows devices but Python doesn't see them, restart audio service
systemctl --user restart pipewire pipewire-pulse wireplumber
# 4. Raspberry Pi Lite: may need to manually install audio server
sudo apt-get install -y pipewire pipewire-pulse wireplumber
systemctl --user enable pipewire pipewire-pulse wireplumber
systemctl --user start pipewire pipewire-pulse wireplumberPulseAudio and PipeWire Conflict
If you installed the pulseaudio daemon by mistake, causing audio issues:
# Remove PulseAudio daemon (keep pactl tools)
sudo apt-get remove -y pulseaudio
sudo apt-get install -y pulseaudio-utils # Only install CLI tools
# Restart PipeWire
systemctl --user restart pipewire pipewire-pulse wireplumbersherpa-onnx Import Failure (macOS)
sherpa-onnx requires the onnxruntime shared library, which may be missing on macOS:
# Download onnxruntime
cd /tmp
curl -sL "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-osx-arm64-1.17.1.tgz" -o onnxruntime.tgz
tar -xzf onnxruntime.tgz
# Copy shared library to sherpa_onnx
cp onnxruntime-osx-arm64-1.17.1/lib/libonnxruntime.1.17.1.dylib \
.venv/lib/python3.10/site-packages/sherpa_onnx/lib/Opus Library Missing
# macOS
brew install opus
# Linux
sudo apt-get install -y libopus0 libopus-devPySide6 Display Issues (Linux)
# Install Qt runtime libraries
sudo apt-get install -y libxcb-xinerama0 libxkbcommon-x11-0 libegl1Package Manager Mirror Setup (for users in mainland China)
pip Mirror
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/uv Mirror
# Set environment variable
export UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
# Or configure in pyproject.toml
# [tool.uv]
# index-url = "https://mirrors.aliyun.com/pypi/simple/"Version Requirements
| Dependency | Version |
|---|---|
| Python | >= 3.10 |
| PySide6 | >= 6.6.0 |
| SoundDevice | >= 0.4.4 |
| FFmpeg | >= 4.0 |
| Opus | >= 1.3 |
| PortAudio | >= 19.0 |
Notes
- Use uv whenever possible to manage dependencies -- it's fast and handles virtual environments automatically
- Python version: Must be >= 3.10; 3.9 and below are not supported
- System dependencies first: Install system dependencies (ffmpeg, opus, portaudio) before Python dependencies
- Don't mix package managers: Choose either uv or pip, not both
- macOS sherpa-onnx: You may need to manually copy the onnxruntime shared library on first run