Quick reference for diagnosing and resolving DLL loading issues in ColdVox's PyO3 bindings.
- Python version matches (3.10-3.12)
- PYTHONHOME is unset
- Visual C++ Redistributables installed (Windows)
- All Python dependencies installed via
uv sync - Rust build completed successfully
- No conflicting Python installations
Symptoms:
ImportError: DLL load failed while importingPython version mismatch- PyO3 initialization fails
Diagnosis:
# Check Python version used
python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')"
# Check .python-version file
cat .python-version
# Verify uv is using correct Python
uv python listSolution:
# Install correct Python version
uv python install 3.12
# Pin to correct version
uv python pin 3.12
# Rebuild Rust crate
cargo clean -p coldvox-stt
cargo build -p coldvox-stt --features moonshineSymptoms:
Py_Initialize: unable to load the file system codecFatal Python error: initfsencoding- PyO3 fails to initialize
Diagnosis:
# Check if PYTHONHOME is set
echo $PYTHONHOME # Linux/macOS
echo %PYTHONHOME% # Windows (cmd)
echo $env:PYTHONHOME # Windows (PowerShell)Solution:
# Unset PYTHONHOME (Linux/macOS)
unset PYTHONHOME
# Unset PYTHONHOME (Windows cmd)
set PYTHONHOME=
# Unset PYTHONHOME (Windows PowerShell)
$env:PYTHONHOME = $null
# Make permanent: Remove from system/user environment variablesSymptoms:
The code execution cannot proceed because MSVCP140.dll was not foundThe code execution cannot proceed because VCRUNTIME140.dll was not foundThe code execution cannot proceed because VCRUNTIME140_1.dll was not found
Diagnosis:
# Check installed VC++ Redistributables
Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "*Visual C++*"}
# Check for required DLLs
Get-ChildItem "C:\Windows\System32\msvcp140.dll" -ErrorAction SilentlyContinue
Get-ChildItem "C:\Windows\System32\vcruntime140.dll" -ErrorAction SilentlyContinue
Get-ChildItem "C:\Windows\System32\vcruntime140_1.dll" -ErrorAction SilentlyContinueSolution:
# Install via winget
winget install Microsoft.VCRedist.2015+.x64
# Or download from Microsoft
# https://aka.ms/vs/17/release/vc_redist.x64.exe
# Restart terminal after installationSymptoms:
ModuleNotFoundError: No module named 'torch'ModuleNotFoundError: No module named 'transformers'ImportError: cannot import name 'X' from 'torch'
Diagnosis:
# Check installed packages
uv pip list
# Check specific package
uv pip show torch
uv pip show transformersSolution:
# Reinstall all dependencies
uv sync
# Or reinstall specific package
uv pip install --force-reinstall torch>=2.0.0
uv pip install --force-reinstall transformers>=4.35.0
# Clear cache if needed
uv cache cleanSymptoms:
- Wrong Python version being used
- DLLs loaded from unexpected locations
ImportErrordespite package being installed
Diagnosis:
# Find all Python installations
where python # Windows
which -a python # Linux/macOS
# Check which Python is being used
python -c "import sys; print(sys.executable)"
# Check PATH
echo $PATH | tr ':' '\n' | grep pythonSolution:
# Use uv to manage Python
uv python install 3.12
uv python pin 3.12
# Verify correct Python
uv run python -c "import sys; print(sys.executable)"
# Remove conflicting Python from PATH if necessarySymptoms:
CUDA error: no kernel image is available for executionlibcudart.so: cannot open shared object filetorch.cuda.is_available()returnsFalse
Diagnosis:
# Check CUDA availability
python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}')"
# Check CUDA version
nvcc --version # Linux
nvidia-smi
# Check CUDA libraries
ldconfig -p | grep cuda # LinuxSolution:
# Install CUDA toolkit (Linux)
sudo apt-get install cuda-toolkit-12-1
# Install CUDA toolkit (Windows)
# Download from NVIDIA: https://developer.nvidia.com/cuda-downloads
# Reinstall PyTorch with CUDA support
uv pip install --force-reinstall torch --index-url https://download.pytorch.org/whl/cu121Symptoms:
libpython3.12.so: cannot open shared object fileerror while loading shared libraries
Diagnosis:
# Check for missing libraries
ldd $(which python) | grep "not found"
# Check library paths
ldconfig -p | grep python
# Check LD_LIBRARY_PATH
echo $LD_LIBRARY_PATHSolution:
# Install Python development headers
sudo apt-get install python3.12-dev
# Update library cache
sudo ldconfig
# Set LD_LIBRARY_PATH if needed
export LD_LIBRARY_PATH=/usr/lib/python3.12/config:$LD_LIBRARY_PATHSymptoms:
coldvox_sttmodule not foundImportError: dynamic module does not define module export function- PyO3 module not loading
Diagnosis:
# Check for compiled module
find target -name "*.pyd" -o -name "*.so" -o -name "*.dylib"
# Check build logs
ls -la target/*/build/coldvox-stt-*/output
# Verify feature flags
grep -A 5 "moonshine" crates/coldvox-stt/Cargo.tomlSolution:
# Clean and rebuild
cargo clean -p coldvox-stt
cargo build -p coldvox-stt --features moonshine
# Verify module exists
find target -name "coldvox_stt*"
# Check Python can import it
uv run python -c "import sys; sys.path.insert(0, 'target/debug'); import coldvox_stt"- Download Process Monitor
- Launch as Administrator
- Set filters:
- Process Name:
python.exe - Operation:
CreateFile - Result:
NAME NOT FOUND
- Process Name:
- Run ColdVox and capture events
- Look for failed DLL loads
# Trace file system access
strace -f -e trace=open,openat -o strace.txt cargo run -p coldvox-app --features moonshine
# Find missing files
grep "ENOENT" strace.txt | grep -E "\.(so|dll)"# Trace library calls
ltrace -e "dlopen,dlsym" -o ltrace.txt cargo run -p coldvox-app --features moonshineAfter applying fixes, verify everything works:
# 1. Check Python environment
uv run python -c "import sys; print(f'Python {sys.version}')"
# 2. Check PyTorch
uv run python -c "import torch; print(f'PyTorch {torch.__version__}'); print(f'CUDA: {torch.cuda.is_available()}')"
# 3. Check Transformers
uv run python -c "import transformers; print(f'Transformers {transformers.__version__}')"
# 4. Check Librosa
uv run python -c "import librosa; print(f'Librosa {librosa.__version__}')"
# 5. Check ColdVox STT
cargo check -p coldvox-stt --features moonshine
# 6. Run full test
cargo test -p coldvox-stt --features moonshineIf issues persist:
- Run the full audit:
./scripts/pyo3_audit.shor.\scripts\pyo3_audit.ps1 - Review the generated
audit_report.md - Check PyO3 Troubleshooting
- Review ColdVox logs with
RUST_LOG=debug cargo run -p coldvox-app --features moonshine