This guide helps you resolve common issues when setting up and running CosyVoice2 API.
For most dependency issues, try running the automatic fix script first:
python scripts/fix_dependencies.pyError:
pydantic.errors.PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package
Solution:
# Install the correct pydantic packages
pip install "pydantic>=2.0.0,<3.0.0"
pip install "pydantic-settings>=2.0.0,<3.0.0"
# Or run the fix script
python scripts/fix_dependencies.pyError:
ImportError: cannot import name 'X' from 'fastapi'
Solution:
# Update FastAPI and related packages
pip install "fastapi>=0.104.0,<1.0.0"
pip install "uvicorn[standard]>=0.24.0,<1.0.0"
pip install "python-multipart>=0.0.6,<1.0.0"Error:
RuntimeError: CUDA error: no kernel image is available for execution on the device
Solutions:
# Check your CUDA version
nvidia-smi
# For CUDA 11.8
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia --force-reinstall
# For CUDA 12.1
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia --force-reinstall
# For CPU-only (fallback)
conda install pytorch torchvision torchaudio cpuonly -c pytorch --force-reinstall# For CUDA 11.8
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# For CUDA 12.1
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# For CPU-only
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpuError:
ImportError: No module named 'librosa'
OSError: cannot load library 'libsndfile.so'
Solutions:
conda install -c conda-forge librosa soundfile -y# Install system dependencies first
# Ubuntu/Debian:
sudo apt-get install libsndfile1-dev
# macOS:
brew install libsndfile
# Then install Python packages
pip install librosa soundfileError:
ConnectionError: Failed to download model
HTTPError: 404 Client Error
Solutions:
# Try different model IDs
python scripts/download_model.py --model-id iic/CosyVoice-300M
python scripts/download_model.py --model-id iic/CosyVoice2-0.5B
# Check internet connection and try again
ping google.com
# Use manual download if needed
# Visit: https://www.modelscope.cn/models/iic/CosyVoice2-0.5BError:
RuntimeError: CUDA out of memory
MemoryError: Unable to allocate array
Solutions:
# Reduce batch size in environment
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512
# Monitor GPU memory
nvidia-smi
# Use CPU-only mode if needed
export CUDA_VISIBLE_DEVICES=""Error:
PermissionError: [Errno 13] Permission denied
Solutions:
# Fix script permissions
chmod +x scripts/*.sh
chmod +x scripts/*.py
# Fix directory permissions
chmod -R 755 voice_cache/ outputs/ logs/
# Don't run as root (create regular user)
sudo useradd -m cosyvoice
sudo su - cosyvoiceError:
OSError: [Errno 98] Address already in use
Solutions:
# Find process using port 8000
lsof -i :8000
# Kill the process
kill -9 <PID>
# Or use different port
python main.py --port 8001
# Or set in environment
export PORT=8001Error:
ModuleNotFoundError: No module named 'cosyvoice'
ModuleNotFoundError: No module named 'app'
ModuleNotFoundError: No module named 'app.models'
Solutions:
# Use the robust startup script
./start_server.sh
# Or use the Python launcher
python run_server.py# Make sure you're in the project directory
cd /path/to/CosyVoice2-API
# Set PYTHONPATH properly
export PYTHONPATH="$(pwd):$(pwd)/cosyvoice_original:$(pwd)/cosyvoice_original/third_party/Matcha-TTS:$PYTHONPATH"
# Then start the server
python main.py# Run the import test
python test_imports.py
# If successful, then start server
python main.pyError:
conda: command not found
pip: command not found
Solutions:
# Activate conda environment
source ~/miniconda3/etc/profile.d/conda.sh
conda activate cosyvoice2-api
# Or activate virtual environment
source venv/bin/activate
# Check which python you're using
which python
which pip# Install system dependencies
sudo apt-get update
sudo apt-get install -y build-essential python3-dev
sudo apt-get install -y ffmpeg libsndfile1-dev
sudo apt-get install -y curl git
# Fix locale issues
export LC_ALL=C.UTF-8
export LANG=C.UTF-8# Install system dependencies
sudo yum update -y
sudo yum groupinstall -y "Development Tools"
sudo yum install -y python3-devel
sudo yum install -y ffmpeg libsndfile-devel
# Enable EPEL repository if needed
sudo yum install -y epel-release# Install Xcode command line tools
xcode-select --install
# Install Homebrew if needed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install dependencies
brew install ffmpeg libsndfile# Install Visual Studio Build Tools
# Download from: https://visualstudio.microsoft.com/visual-cpp-build-tools/
# Install ffmpeg
# Download from: https://ffmpeg.org/download.html
# Add to PATH
# Use Windows Subsystem for Linux (WSL) as alternative
wsl --installIf you have persistent issues, try a clean installation:
# Remove existing environment
conda env remove -n cosyvoice2-api
# Clear pip cache
pip cache purge
# Remove project directory and re-clone
rm -rf CosyVoice2-API
git clone https://github.com/sin-tag/CosyVoice2-API.git
cd CosyVoice2-API
# Run setup again
./scripts/setup_conda.shEnable debug mode for more detailed error messages:
# Set debug environment
export DEBUG=true
export PYTHONPATH="$(pwd):$PYTHONPATH"
# Run with verbose output
python -v main.py
# Check logs
tail -f logs/cosyvoice2-api.logResolve complex dependency conflicts:
# Check for conflicts
pip check
# Create dependency graph
pip install pipdeptree
pipdeptree
# Force reinstall problematic packages
pip install --force-reinstall --no-deps <package_name>If you're still having issues:
- Run the verification script:
python scripts/verify_installation.py - Run the fix script:
python scripts/fix_dependencies.py - Check the logs: Look in
logs/directory for error details - Create an issue: Include the full error message and system info
When reporting issues, include:
# System info
uname -a
python --version
pip --version
conda --version
# Environment info
conda info
conda list
pip list
# GPU info (if applicable)
nvidia-smiThis information helps diagnose the problem quickly!