Package: depthai
DepthAI Python LibraryPython bindings for C++ depthai-core libraryDocumentationDocumentation is available over atLuxonis DepthAI APIInstallationPrebuilt wheels are available inLuxonis repositoryMake sure pip is upgradedpython3 -m pip install -U pip
python3 -m pip install --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local/ depthaiBuilding from sourceDependenciescmake >= 3.4C++14 compiler (clang, gcc, msvc, ...)Python3Along these, dependencies of depthai-core are also required
See:depthai-core dependenciesBuildingThe first time you build, the repository submodules need be initialized:git submodule update --init --recursive

# Tip: You can ask Git to do that automatically:
git config submodule.recurse trueLater submodules also need to be updated.Local build with pipTo build and install using pip:python3 -m pip install .Add parameter-vto see the output of the building process.Wheel with pipTo build a wheel, execute the followingpython3 -m pip wheel . -w wheelhouseShared libraryTo build a shared library from source perform the following:ℹ️ To speed up build times, usecmake --build build --parallel [num CPU cores](CMake >= 3.12).
For older versions use: Linux/macOS:cmake --build build -- -j[num CPU cores], MSVC:cmake --build build -- /MP[num CPU cores]cmake -H. -Bbuild
cmake --build buildTo specify custom Python executable to build for, usecmake -H. -Bbuild -D PYTHON_EXECUTABLE=/full/path/to/python.Common issuesMany build fails due to missing dependencies. This also happens when submodules are missing or outdated (git submodule update --recursive).If libraries and headers are not in standard places, or not on the search paths, CMake reports it cannot find what it needs (e.g.libusb). CMake can be hinted at where to look, for exmpale:CMAKE_LIBRARY_PATH=/opt/local/lib CMAKE_INCLUDE_PATH=/opt/local/include pip install .Some distribution installers may not get the desired library. For example, an install on a RaspberryPi failed, missinglibusb, as the default installation with APT led to v0.1.3 at the time, whereas the library here required v1.0.Running testsTo run the tests build the library with the following optionsgit submodule update --init --recursive
cmake -H. -Bbuild -D DEPTHAI_PYTHON_ENABLE_TESTS=ON -D DEPTHAI_PYTHON_ENABLE_EXAMPLES=ON -D DEPTHAI_PYTHON_TEST_EXAMPLES=ON
cmake --build buildThen navigate tobuildfolder and runctestcd build
ctestTo test a specific example/test with a custom timeout (in seconds) use following:TEST_TIMEOUT=0 ctest -R "01_rgb_preview" --verboseIfTEST_TIMEOUT=0, the test will run until stopped or it ends.Tested platformsWindows 10, Windows 11Ubuntu 18.04, 20.04, 22.04;Raspbian 10;macOS 10.14.6, 10.15.4;Building documentationUsingDocker(withDocker Compose)cd docs
sudo docker-compose build
sudo docker-compose upℹ️ You can leave out thesudoif you have added your user to thedockergroup (or are using rootless docker).
Then openhttp://localhost:8000.This docker container will watch changes in thedocs/sourcedirectory and rebuild the docs automaticallyLinuxFirst, please install the requireddependenciesThen run the following commands to build the docs websitepython3 -m pip install -U pip
python3 -m pip install -r docs/requirements.txt
cmake -H. -Bbuild -D DEPTHAI_BUILD_DOCS=ON -D DEPTHAI_PYTHON_BUILD_DOCS=ON
cmake --build build --target sphinx
python3 -m http.server --bind 0.0.0.0 8000 --directory build/docs/sphinxThen openhttp://localhost:8000.This will build documentation based on current sources, so if some new changes will be made, run this command
in a new terminal window to update the website sourcecmake --build build --target sphinxThen refresh your page - it should load the updated website that was just builtTroubleshootingRelocation link errorBuild failure on Ubuntu 18.04 ("relocation ..." link error) with gcc 7.4.0 (default) -issue #3the solution was to upgrade gcc to version 8:sudo apt install g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 70
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 70HunterHunter is a CMake-only dependency manager for C/C++ projects.If you are stuck with error message which mentions external libraries (subdirectory of.hunter) like the following:/usr/bin/ld: /home/[user]/.hunter/_Base/062a19a/ccfed35/a84a713/Install/lib/liblzma.a(stream_flags_decoder.c.o): warning: relocation against `lzma_footer_magic' in read-only section `.text'Try erasing theHuntercachefolder.Linux/MacOS:rm -r ~/.hunterWindows:del C:/.hunterordel C:/[user]/.hunterLTO - link time optimizationIf following message appears:lto1: internal compiler error: in add_symbol_to_partition_1, at lto/lto-partition.c:152
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.
lto-wrapper: fatal error: /usr/bin/c++ returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/depthai.dir/build.make:227: depthai.cpython-38-x86_64-linux-gnu.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:98: CMakeFiles/depthai.dir/all] Error 2
make: *** [Makefile:130: all] Error 2One fix is to update linker: (In case you are on Ubuntu 20.04:/usr/bin/ld --version: 2.30)# Add to the end of /etc/apt/sources.list:

echo "deb http://ro.archive.ubuntu.com/ubuntu groovy main" >> /etc/apt/sources.list

# Replace ro with your countries local cache server (check the content of the file to find out which is)
# Not mandatory, but faster

sudo apt update
sudo apt install binutils

# Should upgrade to 2.35.1
# Check version:
/usr/bin/ld --version
# Output should be: GNU ld (GNU Binutils for Ubuntu) 2.35.1
# Revert /etc/apt/sources.list to previous state (comment out line) to prevent updating other packages.
sudo apt updateAnother option is to useclangcompiler:sudo apt install clang-10
mkdir build && cd build
CC=clang-10 CXX=clang++-10 cmake ..
cmake --build . --parallel