2.2. Linux Python SDK Compilation
This section provides a comprehensive guide to installing, compiling, and running the Orbbec SDK for Python, covering all necessary steps for setup.
Contents:
Install Dependencies (Ubuntu)
Custom Python Path (Optional)
Build the Project
Run the Examples
Generate Python Stubs
Making a Python Wheel
Clone the repository to get the latest version:
git clone https://github.com/orbbec/pyorbbecsdk.git
git checkout OrbbecSDK_V2.x
2.2.1. Install Dependencies (Ubuntu)
Install the necessary Python development packages
sudo apt-get install python3-dev python3-venv python3-pip python3-opencv
2.2.2. Custom Python Path (Optional)
If you use Anaconda, update the Python path in pyorbbecsdk/CMakeLists.txt
before the find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
line:
set(Python3_ROOT_DIR "/home/anaconda3/envs/py3.6.8") # Replace with your Python path
set(pybind11_DIR "${Python3_ROOT_DIR}/lib/python3.6/site-packages/pybind11/share/cmake/pybind11") # Replace with your Pybind11 path
2.2.3. Build the Project
Create a virtual environment and build the project:
cd pyorbbecsdk
python3 -m venv ./venv
source venv/bin/activate
pip3 install -r requirements.txt
mkdir build
cd build
cmake -Dpybind11_DIR=`pybind11-config --cmakedir` ..
make -j4
make install
2.2.4. Run the Examples
Set up the environment and run the examples:
cd pyorbbecsdk
export PYTHONPATH=$PYTHONPATH:$(pwd)/install/lib/
sudo bash ./scripts/install_udev_rules.sh
sudo udevadm control --reload-rules && sudo udevadm trigger
python3 examples/depth_viewer.py
python3 examples/net_device.py # Requires ffmpeg installation for network devices
2.2.5. Generate Python Stubs
Generate stubs for better IntelliSense support in your IDE
source env.sh
pip3 install pybind11-stubgen
pybind11-stubgen pyorbbecsdk
2.2.6. Making a Python Wheel
To generate a wheel package for easy distribution
cd pyorbbecsdk
python3 -m venv ./venv
source venv/bin/activate
pip3 install -r requirements.txt
mkdir build
cd build
cmake -Dpybind11_DIR=`pybind11-config --cmakedir` ..
make -j4
make install
cd ..
pip3 install wheel
python3 setup.py bdist_wheel
pip3 install dist/*.whl
2.3. Windows Python SDK Compilation
2.3.1. Download the Python SDK Source Code
git clone https://github.com/orbbec/pyorbbecsdk.git
2.3.2. Install Dependencies
pip3 install -r requirements.txt
Here, it is assumed that you have installed Python 3 correctly. If you have not installed Python 3, you can refer to the Python official website and choose your Python 3 version for installation.
2.3.3. Configure Visual Studio Project
Open Cmake, set the source code path, and set the “build” folder as the path for generating binary files, as shown in the following figure.
Click “Configure” and select the corresponding Visual Studio version and platform version. Then click “Finish”, as shown below:
Here, it is assumed that you have installed Cmake correctly. If you have not installed Cmake, you can refer to the Cmake official website for installation.
Click “Generate”, as shown below:
2.3.4. Compile the Python SDK
You can open the Python SDK project in two ways:
Method 1: Use Cmake, click the “Open Project” button, and open the Visual Studio project.
Method 2: Use the file explorer to directly start the Visual Studio project in the build directory, as shown in the following figure:
Open the Python SDK project, as shown below:
Open the Python SDK project, as shown below:
Right-click “INSTALL”, as shown below:
The compiled files will be copied to the install/lib directory, as shown below:
Copy the files in the install/lib directory to the examples directory, as shown below:
2.3.5. Test Examples
In the examples directory, execute test examples such as python ColorViewer.py, as shown below: