Installation - Python

Instructions for installing, upgrading, and using the DepthAI Python API.

Supported Platforms

The DepthAI Gen2 API python module is prebuilt for Ubuntu, macOS and Windows. For other operating systems and/or Python versions, DepthAI can be built from source.

Installing system dependencies

A couple of basic system dependencies are required to run the DepthAI library. Most of them should be already installed in most of the systems, but in case they are not, we prepared an install script that will make sure all dependencies are installed, along with convenient development/programming tools. There are also video guides available for macOS (here), Raspberry Pi (here), Ubuntu (here), and Windows 10 (here).

macOS

bash -c "$(curl -fL http://docs.luxonis.com/_static/install_dependencies.sh)"

Close and re-open the terminal window after this command.

The script also works on M1 Macs, Homebrew being installed under Rosetta 2, as some Python packages are still missing native M1 support. In case you already have Homebrew installed natively and things don’t work, see here for some additional troubleshooting steps.

Note that if the video streaming window does not appear consider running the following:

python3 -m pip install opencv-python --force-reinstall --no-cache-dir

See the Video preview window fails to appear on macOS thread on our forum for more information.

Raspberry Pi OS

sudo curl -fL http://docs.luxonis.com/_static/install_dependencies.sh | bash

Ubuntu

sudo wget -qO- http://docs.luxonis.com/_static/install_dependencies.sh | bash

Windows

  • Right click on Start

  • Choose Windows PowerShell (Admin)

  • Install Chocolatey package manager (similar to Homebrew for macOS):

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  • Close the PowerShell and then re-open another PowerShell (Admin) by repeating the first two steps.

  • Install Python and PyCharm

choco install cmake git python pycharm-community -y

Enabling the USB device (only on Linux)

Since the DepthAI is a USB device, in order to communicate with it on the systems that use udev tool, you need to add the udev rules in order to make the device accessible.

The following command will add a new udev rule to your system

echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="03e7", MODE="0666"' | sudo tee /etc/udev/rules.d/80-movidius.rules
sudo udevadm control --reload-rules && sudo udevadm trigger

Install using pip

Our packages are available to download using our Artifactory server. These are built for every commit in the depthai-python repository and are suffixed with a commit SHA.

Note that we recommend installing the dependencies in a virtual environment, so that they don’t interfere with other Python tools/environments on your system.

  • For development machines like Mac/Windows/Ubuntu/etc., we recommend the PyCharm IDE, as it automatically makes/manages virtual environments for you, along with a bunch of other benefits. Alternatively, conda, pipenv, or virtualenv could be used directly (and/or with your preferred IDE).

  • For installations on resource-constrained systems, such as the Raspberry Pi or other small Linux systems, we recommend conda, pipenv, or virtualenv. To set up a virtual environment with virtualenv, run

    virtualenv venv
    source venv/bin/activate
    

Using a virtual environment (or system-wide, if you prefer), run the following to install the DepthAI using pip:

  1. Pick the preferred commit from commit list

  2. Upgrade pip

python3 -m pip install -U pip
  1. Install DepthAI Gen2 API, adding commit SHA at the end of a package name, in form of depthai==0.0.2.1+<sha>

python3 -m pip install --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local/ depthai==0.0.2.1+c9a19df719cb668e438d6eafd193cdf60a0d9354

For other installation options, see other installation options.

Test installation

We have a set of examples that should help you verify if your setup was correct.

First, clone the depthai-python repository and change directory into this repo:

git clone https://github.com/luxonis/depthai-python.git --branch gen2_develop
cd depthai-python

Now, run the 01_rgb_preview.py script from within :code`examples` directory to make sure everything is working:

python3 examples/01_rgb_preview.py

If all goes well a small window video display will appear with color camera preview

Warning

Some of the examples needs additional setup to be ran. Please be sure to follow setup instructions in README.md to run different examples

Other installation methods

To get the latest features from our source code, you can go ahead and compile depthai package manually.

Dependencies to build from source

  • CMake > 3.2.0

  • Generation tool (Ninja, make, …)

  • C/C++ compiler

  • libusb1 development package

Ubuntu, Raspberry Pi OS, … (Debian based systems)

On Debian based systems (Raspberry Pi OS, Ubuntu, …) these can be acquired by running:

sudo apt-get -y install cmake libusb-1.0-0-dev build-essential

macOS (Mac OS X)

Assuming a stock Mac OS X install, depthai-python library needs following dependencies

  • Homebrew (If it’s not installed already)

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    
  • Python, libusb, CMake, wget

    brew install coreutils python3 cmake libusb wget
    

And now you’re ready to clone the depthai-python gen2_develop branch from Github and build it for Mac OS X.

Using/Testing a Specific Branch/PR

From time to time, it may be of interest to use a specific branch. This may occur, for example, because we have listened to your feature request and implemented a quick implementation in a branch. Or it could be to get early access to a feature that is soaking in for stability purposes before being merged.

So when working in the depthai-python repository, using a branch can be accomplished with the following commands.

Prior to running the following, you can either clone the repository independently (for not over-writing any of your local changes) or simply do a git pull first.

git checkout <branch>
git submodule update --init --recursive
python3 setup.py develop

Install from source

If desired, you can also install the package from the source code itself - it will allow you to make the changes to the API and see them live in action.

To do so, first download the repository and then add the package to your python interpreter in development mode

git clone https://github.com/luxonis/depthai-python.git --branch gen2_develop
cd depthai-python
git submodule update --init --recursive
python3 setup.py develop  # you may need to add sudo if using system interpreter instead of virtual environment