fix: add explicit NumPy version constraints for Python 3.13+ and 3.14 (NumPy 2.x compatibility) - #1223
fix: add explicit NumPy version constraints for Python 3.13+ and 3.14 (NumPy 2.x compatibility)#1223mulhamfetna wants to merge 2 commits into
Conversation
- Changed install_requires to specify minimum numpy versions per Python version: - Python 3.9-3.12: numpy>=2.0.2 - Python 3.13: numpy>=2.1.3 - Python 3.14+: numpy>=2.3.0 - This fixes NumPy 2.x ABI compatibility issue where wheels compiled against NumPy 1.x fail at runtime with NumPy 2.x Fixes opencv#1201
| 'numpy>=2.0.2; python_version>="3.9" and python_version<"3.13"', | ||
| 'numpy>=2.1.3; python_version>="3.13" and python_version<"3.14"', | ||
| 'numpy>=2.3.0; python_version>="3.14"', |
There was a problem hiding this comment.
Why the overly restrictive patch version pin ?
| 'numpy>=2.0.2; python_version>="3.9" and python_version<"3.13"', | |
| 'numpy>=2.1.3; python_version>="3.13" and python_version<"3.14"', | |
| 'numpy>=2.3.0; python_version>="3.14"', | |
| 'numpy>=2.0; python_version>="3.9" and python_version<"3.13"', | |
| 'numpy>=2.1; python_version>="3.13" and python_version<"3.14"', | |
| 'numpy>=2.3; python_version>="3.14"', |
python_version< should also be redundant, given that on higher python versions, the numpy version is already restricted to a higher bound.
Unlocking the pin was also handled in 7bd1825
There was a problem hiding this comment.
Good catch, thanks — the patch-level pins weren't deliberate, just over-specific. Applied your suggestion.
One small deviation: I kept a patch-level floor for 3.14. Checking PyPI, 2.3.0 and 2.3.1 ship no cp314 wheels — 2.3.2 is the first release that does — so >=2.3.2 is the accurate floor there. >=2.1 for 3.13 matches the same way, since 2.1.0 is the first with cp313 wheels.
Happy to drop the python_version< upper bounds as you suggested if you'd prefer — they are redundant, since the highest applicable floor wins. I left them only because your snippet kept them; say the word and I'll simplify.
Address review feedback from @Avasam: the patch-level pins were unnecessarily specific. Lower bounds now track the first NumPy release providing wheels for each interpreter: - numpy 2.1.0 is the first release with cp313 wheels - numpy 2.3.2 is the first release with cp314 wheels (2.3.0 and 2.3.1 ship none), so the Python 3.14 floor stays at the patch level
Summary
Changes
Root Cause
The wheel metadata declared as dependency at install time, but the compiled wheels may have been built against NumPy 1.x headers, causing ABI incompatibility at runtime.
Fixes #1201