Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
CameronDevine opened this issue Jan 9, 2025 · 6 comments
Open
4 tasks done
Assignees

Comments

@CameronDevine
Copy link

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)
@opencv-alalek
Copy link
Contributor

You need to take a look in direction of numpy build configuration first. Error message comes from there.

@asmorkalov
Copy link
Contributor

Related: opencv/opencv-python#1029

@asmorkalov
Copy link
Contributor

Related opencv/opencv-python#1051

@CameronDevine
Copy link
Author

@asmorkalov I tried adding -DPYTHON3_LIMITED_API=OFF to my CMake command, but I am still getting the same error.

@CameronDevine
Copy link
Author

@opencv-alalek, I opened an issue in the NumPy repository, but it seems like everything is pointing back towards this being an OpenCV issue. numpy/numpy#28138

@sergregory sergregory self-assigned this Jan 12, 2025
@ngoldbaum
Copy link

Happy to answer questions about free-threading support. I did a lot of the work for NumPy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants