4.1. Build from Source with UV (Recommended)
This guide explains how to build pyorbbecsdk wheel packages using uv, a fast Python package manager and resolver. The UV-based build system provides significant advantages over traditional pip/venv workflows:
Fast dependency resolution: UV resolves dependencies 10-100x faster than pip
Automatic Python version management: UV can install and manage multiple Python versions
Automatic virtual environments: UV creates and manages isolated environments automatically
Offline support: Build without internet access using cached dependencies
Cross-platform: Unified build process across Linux, macOS, and Windows
Reproducible builds: Consistent environment setup across different machines
💡 Prefer traditional virtual environments?
If you prefer using standard
venv,pyenv, orcondainstead of UV, see the Virtual Environment Installation Guide for alternative setup instructions.
4.1.1. Prerequisites
4.1.1.1. All Platforms
Install uv: Follow the official uv installation guide
# Linux/macOS curl -LsSf https://astral.sh/uv/install.sh | sh # Windows PowerShell powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
Verify uv installation:
uv --versionInstall CMake (3.15.0 or higher):
Download from CMake official website
Or install via package manager
Verify Build Environment:
Before building, verify that the required compiler tools are installed:
Linux/macOS
# Check CMake version (requires 3.15.0+) cmake --version # Check GCC version (requires 7.4.0+) gcc --version g++ --version
Windows
# Check CMake version cmake --version # Check Visual Studio installation # Option 1: Using vswhere (if installed with VS) & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath # Option 2: Check for cl.exe Get-Command cl.exe -ErrorAction SilentlyContinue
CMake and Visual Studio Version Compatibility (Windows):
Visual Studio Version |
Minimum CMake Version |
|---|---|
Visual Studio 2019 |
3.15.0+ |
Visual Studio 2022 |
3.20.0+ |
Visual Studio 2026 |
4.2.0+ |
If any command fails, refer to the Platform-Specific Requirements section below.
Clone the repository:
git clone https://github.com/orbbec/pyorbbecsdk.git cd pyorbbecsdk git checkout v2-main
4.1.1.2. Platform-Specific Requirements
4.1.1.2.1. Linux
GCC 7.4.0 or higher
Python development headers
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install python3-dev build-essential
# CentOS/RHEL/Fedora
sudo yum install python3-devel gcc-c++
4.1.1.2.2. macOS
Xcode Command Line Tools
Clang/Clang++ compiler
# Install Xcode Command Line Tools
xcode-select --install
4.1.1.2.3. Windows
Visual Studio 2019 or 2022 with C++ build tools
Windows SDK
4.1.2. Build Scripts
The project provides platform-specific UV build scripts:
Platform |
Script |
|---|---|
Linux |
|
macOS |
|
Windows |
|
Note: These scripts are available in the
feature/uv_clibranch. To use them, switch to that branch or copy the scripts to your working directory.
4.1.3. Quick Start
4.1.3.1. Linux
# Make the script executable
chmod +x scripts/build_whl/build-whl-uv.sh
# Build for Python 3.10 (default)
./scripts/build_whl/build-whl-uv.sh
# Build for specific Python version
./scripts/build_whl/build-whl-uv.sh 3.11
# Build for multiple Python versions
./scripts/build_whl/build-whl-uv.sh 3.9 3.10 3.11
# Build the all-version batch (3.8-3.13); pass 3.14 explicitly for Python 3.14
./scripts/build_whl/build-whl-uv.sh all
4.1.3.2. macOS
# Make the script executable
chmod +x scripts/build_whl/build-whl-uv-macos.sh
# Build for Python 3.10 (default)
./scripts/build_whl/build-whl-uv-macos.sh
# Build for specific Python version
./scripts/build_whl/build-whl-uv-macos.sh 3.11
# Build for multiple Python versions
./scripts/build_whl/build-whl-uv-macos.sh 3.9 3.10 3.11
# Build the all-version batch (3.8-3.13); pass 3.14 explicitly for Python 3.14
./scripts/build_whl/build-whl-uv-macos.sh all
4.1.3.3. Windows
# Build for Python 3.10 (default)
.\scripts\build_whl\build-whl-uv.ps1
# Note: The Windows script currently builds configured versions in the script
# Edit $PythonVersions array in the script to change target versions
4.1.4. Script Options
All build scripts support the following command-line options:
Option |
Description |
|---|---|
|
Enable offline mode (requires pre-cached dependencies) |
|
Skip cleaning build directories before building |
|
Clean build directories before building (default) |
|
Only clean build artifacts, don’t build |
|
Show help message |
4.1.4.1. Examples
# Offline build for Python 3.10
./scripts/build_whl/build-whl-uv.sh --offline 3.10
# Clean and build all versions
./scripts/build_whl/build-whl-uv.sh --clean all
# Only clean build artifacts
./scripts/build_whl/build-whl-uv.sh --clean-only
# Build without cleaning (incremental build)
./scripts/build_whl/build-whl-uv.sh --no-clean 3.11
4.1.5. Offline Build
Offline builds require matching OS/architecture, locally available Python interpreters, the native compiler/CMake toolchain and SDK libraries, and a populated uv cache. Copying the repository or virtual environments alone is not sufficient.
4.1.5.1. Prepare the cache online
On a matching online machine, complete the actual build once for every required Python version and platform. This caches pybind11, the isolated wheel build dependencies, and the tools needed on Linux to repair wheels and adjust their platform tags (auditwheel and wheel). Do not use an editable install of the project to prepare a clean checkout: the package backend requires CMake output in install/lib first.
# Linux example; use the macOS or Windows script on those platforms.
./scripts/build_whl/build-whl-uv.sh 3.10
uv cache dir
uv python dir
Transfer the project, the cache printed by uv cache dir, and any required uv-managed Python installations to the offline machine. Preserve cache contents; do not run cache pruning before transfer. Provide the compiler, CMake and system libraries separately. Virtual environments are not generally relocatable; recreate them on the target or use a locally prepared environment with valid interpreter paths. Repeat preparation for Python 3.14 explicitly if needed; all covers only 3.8 through 3.13.
4.1.5.2. Default offline build
Set the cache and Python installation locations to the copied directories, then use the platform’s offline flag:
# Linux; replace these paths with the transferred cache/interpreter directories.
export UV_CACHE_DIR=/path/to/copied-uv-cache
export UV_PYTHON_INSTALL_DIR=/path/to/copied-uv-python
./scripts/build_whl/build-whl-uv.sh --offline 3.10
# macOS: ./scripts/build_whl/build-whl-uv-macos.sh --offline 3.10
# Windows PowerShell
$env:UV_CACHE_DIR = "C:\offline\uv-cache"
$env:UV_PYTHON_INSTALL_DIR = "C:\offline\uv-python"
.\scripts\build_whl\build-whl-uv.ps1 3.10 -Offline
The default mode deletes and recreates the per-version environment and installs only pinned pybind11 into it. Packaging dependencies are installed separately by uv build in an isolated build environment. The offline flag sets UV_OFFLINE=1; missing cached dependencies or interpreters cause failure rather than being supplied by a copied venv* directory.
4.1.5.3. Reuse an active environment
To retain a locally prepared environment, activate it and add the script’s --no-sync option (PowerShell: -NoSync). The active Python version must match the requested version, and pybind11 must already be installed in that environment. For offline packaging, the isolated build dependencies must still be available in the uv cache. For example:
source .venv/bin/activate
./scripts/build_whl/build-whl-uv.sh --offline --no-sync 3.10
# macOS: ./scripts/build_whl/build-whl-uv-macos.sh --offline --no-sync 3.10
This mode skips environment recreation and pinned pybind11 installation. It still performs CMake compilation and uv build, whose isolated build requirements must be cached. It is not a guarantee that an arbitrary copied environment can build offline.
4.1.6. Build Output
After successful build, wheel packages are located in:
pyorbbecsdk/
└── wheel/
├── pyorbbecsdk2-2.0.XX-cp38-cp38-linux_x86_64.whl
├── pyorbbecsdk2-2.0.XX-cp39-cp39-linux_x86_64.whl
├── pyorbbecsdk2-2.0.XX-cp310-cp310-linux_x86_64.whl
├── pyorbbecsdk2-2.0.XX-cp313-cp313-linux_x86_64.whl
├── pyorbbecsdk2-2.0.XX-cp314-cp314-linux_x86_64.whl
└── ...
4.1.6.1. Installing the Wheel
Replace the example filename with your built wheel. For wrapper 2.1.4 and
later, include [examples] to run the SDK examples; omit it for a core-only
installation. Quote the entire argument so shell bracket expansion does not
interfere.
# Install the wheel package
pip install "wheel/pyorbbecsdk2-2.1.4-cp310-cp310-linux_x86_64.whl[examples]"
# Verify installation
pip show pyorbbecsdk2 | grep Version
4.1.6.2. Generate Type Stubs (Optional but Recommended)
From the repository root, activate the environment containing the newly built SDK. Stub generation inspects that installed package; rebuild/install the SDK first when bindings change. Follow the same package layout as stubs/README.md:
python -m pip install pybind11-stubgen
python -m pybind11_stubgen pyorbbecsdk -o generated_stubs
python scripts/fix_pyi.py generated_stubs/pyorbbecsdk/pyorbbecsdk.pyi stubs/pyorbbecsdk.pyi
python scripts/fix_pyi.py generated_stubs/pyorbbecsdk/__init__.pyi stubs/__init__.pyi
If the environment has no pip, first activate the intended virtual environment. Replace .venv with your actual environment directory:
Platform / shell |
Activation command |
|---|---|
Linux / macOS |
|
Windows PowerShell |
|
Windows Command Prompt |
|
Verify the active interpreter, then let uv install the tool into that activated environment:
python -c "import sys; print(sys.executable)"
uv pip install pybind11-stubgen
python -m pybind11_stubgen pyorbbecsdk -o generated_stubs
Use the same activated environment for the repair and copy commands above and below. The platform-specific interpreter paths are .venv/bin/python on Linux/macOS and .venv\Scripts\python.exe on Windows; do not use the Linux path on Windows. Both package and extension stubs must be repaired and copied together:
from pathlib import Path
import shutil
import pyorbbecsdk
package_dir = Path(pyorbbecsdk.__file__).resolve().parent
for name in ("pyorbbecsdk.pyi", "__init__.pyi"):
shutil.copy2(Path("stubs") / name, package_dir / name)
print(package_dir)
4.1.7. Build Process Details
The build scripts perform the following steps:
Parse Arguments: Process command-line options and Python versions
Architecture Detection: Detect system architecture (x86_64, arm64)
Environment Setup: Configure library paths for the SDK
Cleanup (optional): Remove previous build artifacts
Per-Version Build:
Resolve Python interpreter using UV
Resolve pybind11 CMake directory
Configure with CMake (using appropriate compiler)
Build and install targets
Copy runtime files (examples, config, stubs)
Build wheel package using
uv buildRepair wheel with auditwheel (Linux only)
Final Cleanup: Remove temporary build directories
4.1.7.1. Key Differences by Platform
Feature |
Linux |
macOS |
Windows |
|---|---|---|---|
Compiler |
GCC/G++ |
Clang/Clang++ |
MSVC |
Library Path |
|
|
PATH |
Architecture |
x86_64, arm64 |
arm64 |
x64 |
Wheel Repair |
auditwheel |
None needed |
None needed |
Deployment Target |
- |
macOS 11.0 (build target; tested on M2/macOS 13.2) |
- |
4.1.8. Troubleshooting
4.1.8.1. Common Issues
4.1.8.1.1. “uv: command not found”
Solution: Ensure uv is installed and in your PATH:
# Add to ~/.bashrc or ~/.zshrc
export PATH="$HOME/.local/bin:$PATH"
4.1.8.1.2. “CMake configuration failed”
Solution: Verify CMake version and Python development headers:
# Check CMake version
cmake --version
# Install Python development headers (Linux)
sudo apt-get install python3-dev
4.1.8.1.3. “pybind11 not found” (Offline mode)
Solution: Follow Offline Build and choose the preparation steps that match the build mode:
Default mode: The script deletes and recreates
venv<version>, then installs pinned pybind11 from the uv cache. Installing pybind11 intovenv310beforehand does not preserve it through this process or supply all missing cached dependencies. Prepare the complete cache, interpreters and toolchain as described above.Reuse an environment: Activate a valid local environment with pybind11 already installed and a Python version matching the requested version, then pass
--offline --no-sync(PowerShell:-Offline -NoSync). This skips environment recreation and pinned pybind11 installation; the isolated wheel build still requires cached build dependencies. Merely creating an environment without activating it and selecting this mode is insufficient.
4.1.8.1.4. “Permission denied” on macOS
Solution: Fix library permissions:
chmod +x scripts/build_whl/build-whl-uv-macos.sh
4.1.8.1.5. Build fails on Windows with “Visual Studio not found”
Solution: Ensure Visual Studio 2019 or 2022 with C++ tools is installed, or specify the generator explicitly:
# In the PowerShell script, modify the cmake command
cmake -G "Visual Studio 17 2022" -A x64 ...
4.1.8.2. Cleaning Build Artifacts
If you encounter persistent build issues, perform a full clean:
# Using the script
./scripts/build_whl/build-whl-uv.sh --clean-only
# Manual cleanup
rm -rf build build_* dist install wheel src/*.egg-info
4.1.9. Advanced Usage
4.1.9.1. Customizing Python Versions
Edit the build script to change default Python versions:
# In scripts/build_whl/build-whl-uv.sh, modify:
PYTHON_VERSIONS=("3.10" "3.11") # Your desired versions
4.1.9.2. Parallel Builds
The scripts automatically use all available CPU cores:
Linux:
make -j$(nproc)macOS:
make -j$(sysctl -n hw.ncpu)Windows:
cmake --build --parallel
4.1.9.3. Environment Variables
Variable |
Description |
|---|---|
|
Set to |
|
Set to |
|
Build deployment target (script sets 11.0; tested on M2/macOS 13.2) |
4.1.10. Comparison with Traditional Build
Feature |
Traditional (pip/venv) |
UV Build |
|---|---|---|
Python Installation |
Manual |
Automatic |
Dependency Resolution |
pip |
UV (faster) |
Virtual Environment |
Manual |
Automatic |
Offline Support |
Limited |
Full support |
Cross-Platform |
Different commands |
Unified scripts |
Build Time |
Slower |
Faster |
4.1.11. Next Steps
After building the wheel:
Install the wheel:
pip install wheel/*.whlSet up environment: Run
scripts/env_setup/install_udev_rules.sh(Linux)Run examples: See
examples/directory for sample codeRefer to registration script: See registration_script.md for device setup
4.1.12. See Also
Install the Package - Installing pre-built wheels
Build from Source - Traditional CMake build method