Python Development

This section explains how to use the ZED SDK in Python 3 on Windows and Linux platforms.

Getting Started

The Python API is an open-source wrapper around the ZED SDK which is written in C++ optimized code. We make the ZED SDK accessible from external Python code using Cython.

To start using the ZED SDK in Python, you will need to download and install the following dependencies on your system:

Installation

Install the ZED SDK according to the Installation Guide.

Install Python and the pip package manager. If these packages are already installed, open a terminal and verify that your Python version is 3.5 or higher.

python --version
pip --version
python3 --version
pip3 --version

Make sure that you have installed an x64 version of Python to avoid errors at compilation. You can check whether Python shell is executing in 32-bit or 64-bit mode by adding the following lines to a Python source code file:

# Returns 32 for 32-bit and 64 for 64-bit
import struct
print(struct.calcsize("P") * 8)

Install Cython and Numpy via pip in a terminal.

pip install cython numpy
pip3 install cython numpy

Building the Python API from Source

Download the ZED Python API sources and extract the archive into a folder. You can also clone the Github repository using the following command.

git clone https://github.com/stereolabs/zed-python-api

Now you can build the plugin. To do that, open a terminal in the folder where you have extracted or cloned the sources of the ZED Python API, such as /path/to/zed-python-api. Then type the following commands.

python setup.py build
python setup.py install
python3 setup.py build
python3 setup.py install

The packages .pyd for Windows or .so for Linux will be generated and installed. You can use python setup.py cleanall to remove all the cpp files generated in the build directory.

Note: Make sure to launch this command outside of the plugin directory. It will prevent Python from considering the pyzed folder of the plugin as the pyzed package.

Using the Python API

Simply import the pyzed package in your Python source code file or terminal to start using the ZED SDK functions.

import pyzed.sl as sl

Check out the ZED Python API tutorials and examples to get started with Python development using the different modules of the ZED SDK.