Poor compatibility with Python 3.14+NumPy 2.3.3
This issue was raised last year, but the version involved was Py 3.10 and 3.11, so an additional issue is being proposed for compatibility with the new version.
Python 3.14.0 (tags/v3.14.0:ebf955d, Oct 7 2025, 10:15:03) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.3.3 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "R:\Python314\Lib\_pyrepl\main.py", line 58, in interactive_console
run_multiline_interactive_console(console)
File "R:\Python314\Lib\_pyrepl\simple_interact.py", line 151, in run_multiline_interactive_console
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
File "R:\Python314\Lib\code.py", line 324, in push
more = self.runsource(source, filename, symbol=_symbol)
File "R:\Python314\Lib\_pyrepl\console.py", line 226, in runsource
result = self.runcode(code)
File "R:\Python314\Lib\_pyrepl\console.py", line 181, in runcode
exec(code, self.locals)
File "<python-input-0>", line 1, in <module>
import cv2
File "W:\cv2\__init__.py", line 181, in <module>
bootstrap()
File "W:\cv2\__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "R:\Python314\Lib\importlib\__init__.py", line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
import cv2
File "W:\cv2\__init__.py", line 181, in <module>
bootstrap()
~~~~~~~~~^^
File "W:\cv2\__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "R:\Python314\Lib\importlib\__init__.py", line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: numpy.core.multiarray failed to import
>>>
after downgraded to np1.26.4:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
opencv-contrib-python 4.13.0.90 requires numpy>=2; python_version >= "3.9", but you have numpy 1.26.4 which is incompatible.
opencv-python 4.13.0.90 requires numpy>=2; python_version >= "3.9", but you have numpy 1.26.4 which is incompatible.
(note:it requires numpy2 while installation, but numpy 1 during runtime) (WHAT THE F**K IS THIS???
.take-issue
This is a critical build metadata issue. The package declares numpy>=2 as dependency at install time, but fails at runtime with NumPy 2.x due to ABI incompatibility.
Root cause: The wheels are compiled against NumPy 1.x headers but the metadata requires NumPy 2.x, causing the mismatch.
Solutions to consider:
- Dual wheel approach: Build wheels for both NumPy 1.x and 2.x
- Use pybind11>=2.12: Rebuild with newer pybind11 that supports NumPy 2.x
- Loosen dependency: Allow
numpy<2until NumPy 2.x compatible wheels are ready
This affects all users who install opencv-python with Python 3.14+. The package becomes unusable without workarounds.
I have experience with similar C++ build issues in OpenCV core (Integer overflow #28930, Unicode paths #21960). Happy to help debug the build configuration if needed.
I've worked on Python compatibility issues (PR #1222 for distutils).
Technical Analysis: NumPy 2.x introduced breaking changes in array API, including different array dtype representation and API functions. opencv-python compiled against NumPy 1.x may not be compatible with NumPy 2.x at runtime.
Root Cause:
- NumPy 2.x changed array type representations
- Python 3.14 may have API changes affecting pybind11
- ABI compatibility between NumPy versions
Fix Strategy:
- Update pybind11 to version supporting NumPy 2.x
- Ensure wheels are built against NumPy 2.x headers
- Add runtime detection and compatibility handling
Related Issues:
- #1211 (NumPy 1.x incompatibility)
- #1149 (NumPy module crash)
Happy to help fix this critical compatibility issue.
I've created a fix for this issue in PR #1223.
Root Cause Analysis: The issue is caused by a mismatch between NumPy version constraints in the package metadata and the NumPy version used during wheel compilation:
- At install time: pip sees numpy>=2 dependency and installs NumPy 2.x
- At runtime: The compiled wheel may have been built against NumPy 1.x headers, causing ABI incompatibility
This creates the contradiction noted in the issue: requires numpy>=2 at install, but requires numpy<2 at runtime
Fix: Changed install_requires in setup.py to specify explicit minimum NumPy versions:
- Python 3.9-3.12: numpy>=2.0.2
- Python 3.13: numpy>=2.1.3
- Python 3.14+: numpy>=2.3.0
This ensures:
- Users get a NumPy version compatible with their Python version at install time
- The minimum version is high enough to be compatible with how wheels are built
PR: https://github.com/opencv/opencv-python/pull/1223
opencv-python 4.13.0.92 segfaults on Python 3.14t (free-threaded) with NumPy 2.x — ABI table layout mismatch
Detailed diagnostic from building a cp314t wheel from opencv-python tag 92 against numpy==2.4.6. We hit a chain of issues, all but the last one resolvable by build-script patches. The final issue appears to be a genuine ABI mismatch between opencv 4.13.0's compiled PyArray_API table offsets and what numpy 2.x's cp314t-win_amd64.pyd provides at runtime.
Build setup
- Windows 2022 GHA runner, MSVC 19.44
uv python install cpython-3.14t→ Python 3.14.5+freethreaded- Build venv:
numpy==2.4.6 setuptools<70.0.0 scikit-build>=0.14 cython>=3.1,<3.2 - CMake: opencv-python's normal CMakeLists, scikit-build orchestration
- Custom patches applied via workflow:
- PR #1051's one-line fix:
-DPYTHON3_LIMITED_API=OFFwhenPy_GIL_DISABLED(so wheel tag iscp314-cp314t-win_amd64notabi3) pyconfig.h: rewrite#pragma comment(lib,"python314.lib")→python314t.lib(cp314t ships only thetvariant)pyproject.toml [build-system].requires: bumpnumpy==2.3.2; python_version=='3.14'→numpy==2.4.6(2.3.2 had the same root issue)setup.py install_requires: tighten thenumpy>=2runtime pin per PR #1223's structure, withnumpy>=2.4.6floor on Python 3.14cv2.hppline 37: changeNPY_NO_DEPRECATED_API NPY_1_7_API_VERSION→NPY_2_0_API_VERSION; add#define NPY_TARGET_VERSION NPY_2_0_API_VERSION- numpy's
__multiarray_api.hline 1512: replacePyCapsule_CheckExact(c_api)withPyCapsule_IsValid(c_api, NULL)— see "the PyCapsule type check" section below
- PR #1051's one-line fix:
Failure chain
Symptom 1 (resolved by patches 1–3): wheel originally built as abi3, then with python314.lib link failure, then with numpy==2.3.2-induced RuntimeError: _ARRAY_API is not PyCapsule object.
Symptom 2 (post-patches 1–5): RuntimeError: _ARRAY_API is not PyCapsule object even with numpy 2.4.6 at build and runtime. Diagnostic on a Python 3.14.3-freethreaded venv:
from numpy._core import _multiarray_umath as mu
api = mu._ARRAY_API
import ctypes
ctypes.pythonapi.PyCapsule_IsValid.restype = ctypes.c_int
ctypes.pythonapi.PyCapsule_IsValid.argtypes = [ctypes.py_object, ctypes.c_char_p]
print(ctypes.pythonapi.PyCapsule_IsValid(api, None)) # → 1 (valid!)
print(id(type(api)) == ctypes.addressof(
ctypes.c_void_p.in_dll(ctypes.pythonapi, 'PyCapsule_Type'))) # → True
So the capsule is genuinely valid and type(api) is PyCapsule_Type per ctypes.pythonapi. Yet cv2.pyd's macro-inlined PyCapsule_CheckExact (which is Py_IS_TYPE(op, &PyCapsule_Type), a header pointer comparison) returns false. Replacing the macro with PyCapsule_IsValid(c_api, NULL) (the exported DLL function) bypasses the check successfully.
This suggests cv2.pyd's inlined &PyCapsule_Type reference resolves to a different address than numpy's _multiarray_umath.cp314t-win_amd64.pyd sees — possibly a Windows / cp314t / linker-table quirk where the type-object address read through cv2's import table differs from the one numpy tagged its capsule with.
Symptom 3 (post all patches): Windows fatal exception: access violation / segfault inside PyInit_cv2, after import_array() returns successfully:
Current thread 0x000018fc (most recent call first):
File "
if (NPY_VERSION != PyArray_GetNDArrayCVersion()) { … } PyArray_GetNDArrayCVersion() is called via PyArray_API0. If the table layout cv2 was compiled against doesn't match what numpy 2.4.6 (cp314t) provides at runtime, the offset-0 dispatch jumps to garbage → segfault.
Why this isn't fixable downstream NPY_TARGET_VERSION=NPY_2_0_API_VERSION only controls which numpy symbols are exposed to consuming code; it doesn't change the runtime PyArray_API table layout numpy itself ships. Tag 92's cv2.hpp line 37 setting NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION is a hint that opencv-python's source hasn't been migrated to numpy 2.x's API conventions, but bumping that define isn't sufficient — the compiled binary still expects offsets/indices that numpy 2.x doesn't promise stability for.
PR #1223 addresses the install-time numpy pin metadata but doesn't change anything compiled. PR #1175 is Python test fixes only.
Reproducer Full workflow is at https://github.com/derekthirstrup/opencv-python/blob/claude/opencv-cp314t-wheel-build-EAmIj/.github/workflows/py-build-314.yml (14 incremental commits walking through each fix). Wheel artifact still available from a recent run if reviewers want to reproduce locally.
What I think needs to happen opencv-python's source needs:
cv2.hpp bumped to NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION (or higher) — already proposed in spirit by reviewer comments on PR #1170 Possibly: ensure all calls into PyArray_API use functions/types that numpy 2.x still guarantees, not deprecated 1.x ones CI matrix for cp313t + cp314t to catch this category of bug Happy to provide the wheel artifact, more diagnostic dumps, or test patches.
opencv-python-headless 4.13.0.92+py314 (cp314t) Latest @github-actions github-actions released this 35 minutes ago v4.13.0.92+py314 5d0d7db Free-threading-compatible (cp314t) wheels for opencv-python-headless, built with the one-line patch from opencv/opencv-python#1051:
-DPYTHON3_LIMITED_API=OFF when Py_GIL_DISABLED is set This produces a real cp314t-tagged binary instead of abi3, so it actually loads under Python 3.14 free-threaded on Windows where python3.dll (the abi3 forwarder) is not present.
Upstream tracking: opencv/opencv-python#1051 (pending merge as of build time). here is a wheel for 3.14t. https://github.com/derekthirstrup/opencv-python/releases/tag/v4.13.0.92%2Bpy314
Is there any update on when this will be fixed?