Skip to content

RuntimeError: _ARRAY_API is not PyCapsule object on Python 3.13 with no GIL #26745

Description

@CameronDevine

System Information

  • OpenCV 4.10.0
  • Ubuntu 22.04
  • Python 3.13 with no GIL
  • Numpy 2.2.1

Detailed description

I am trying to build OpenCV with bindings using Python 3.13 with no GIL. I am able to build OpenCV, but when trying to import cv2 I get an error: RuntimeError: _ARRAY_API is not PyCapsule object.

Steps to reproduce

Build a docker container using the following dockerfile:

FROM nvidia/cuda:12.3.2-devel-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get install -y cmake build-essential zip python3.13-nogil python3.13-dev

ADD https://bootstrap.pypa.io/get-pip.py /
RUN python3.13t /get-pip.py
RUN python3.13t -m pip install numpy

ADD https://github.com/opencv/opencv/archive/refs/tags/4.10.0.zip /opencv.zip
RUN unzip /opencv.zip
ADD https://github.com/opencv/opencv_contrib/archive/refs/tags/4.10.0.zip /opencv_contrib.zip
RUN unzip /opencv_contrib.zip

RUN mkdir build
RUN bash -c "cmake \
  -S /opencv-4.10.0 \
  -B /build \
  -DOPENCV_EXTRA_MODULES_PATH='/opencv_contrib-4.10.0/modules/cudev;/opencv_contrib-4.10.0/modules/cudaarithm;/opencv_contrib-4.10.0/modules/cudaimgproc;/opencv_contrib-4.10.0/modules/cudawarping' \
  -DBUILD_TESTS=OFF \
  -DBUILD_PERF_TESTS=OFF \
  -DBUILD_opencv_apps=OFF \
  -DWITH_OPENCL=OFF \
  -DWITH_PNG=OFF \
  -DWITH_JPEG=OFF \
  -DWITH_WEBP=OFF \
  -DWITH_OPENJPEG=OFF \
  -DWITH_JASPER=OFF \
  -DWITH_OPENEXR=OFF \
  -DWITH_JPEGXL=OFF \
  -DWITH_V4L=OFF \
  -DWITH_FFMPEG=OFF \
  -DWITH_GSTREAMER=OFF \
  -DWITH_ANDROID_MEDIANDK=OFF \
  -DVIDEOIO_ENABLE_PLUGINS=OFF \
  -DWITH_GTK=OFF \
  -DPARALLEL_ENABLE_PLUGINS=OFF \
  -DHIGHGUI_ENABLE_PLUGINS=OFF \
  -DWITH_PROTOBUF=OFF \
  -DBUILD_PROTOBUF=OFF \
  -DOPENCV_DNN_OPENCL=OFF \
  -DENABLE_CCACHE=OFF \
  -DBUILD_JAVA=OFF \
  -DBUILD_opencv_python2=OFF \
  -DBUILD_opencv_dnn=OFF \
  -DBUILD_opencv_gapi=OFF \
  -DBUILD_opencv_highgui=OFF \
  -DBUILD_opencv_flann=ON \
  -DBUILD_opencv_objdetect=OFF \
  -DBUILD_opencv_videoio=OFF \
  -DBUILD_opencv_video=OFF \
  -DBUILD_opencv_photo=OFF \
  -DBUILD_opencv_stitching=OFF \
  -DBUILD_opencv_world=OFF \
  -DBUILD_opencv_ml=OFF \
  -DBUILD_opencv_calib3d=OFF \
  -DBUILD_opencv_python3=ON \
  -DPYTHON_EXECUTABLE=$(which python3.13t) \
  -DOPENCV_PYTHON3_INSTALL_PATH=lib/python3.13t/dist-packages \
  -DPYTHON3_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython3.13t.so \
  -DWITH_CUDA=OFF 2>&1 \
    | tee /cmake.log"
RUN bash -c "make -C /build -j $(nproc) 2>&1 | tee /build.log"
RUN bash -c "make -C /build install 2>&1 | tee /install.log"

Then, inside the container run python3.13t -c "import cv2"

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions