Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
2.11.1
Problem description
Hi pybind11 devs, I'd like to request a new release to support numpy 2.0. The first release candidate for numpy 2.0 is expected in early February. The underlying issue for 2.0 support was addressed ~3 months ago in gh-4857.
Right now, numpy
is trying to warn users testing a nightly or main
that there is an issue when digging into private internals of numpy, and the message specifically mentions pybind11
not being compatible (most probably root cause):
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0.dev0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled against NumPy 2.0.
If you are a user of the module, the easiest solution will be to
either downgrade NumPy or update the failing module (if available).
NOTE: When testing against pre-release versions of NumPy 2.0
or building nightly wheels for it, it is necessary to ensure
the NumPy pre-release is used at build time.
The main way to ensure this is using no build isolation
and installing dependencies manually with NumPy.
For cibuildwheel for example, this may be achieved by using
the flag to pip:
CIBW_BUILD_FRONTEND: pip; args: --no-build-isolation
installing NumPy with:
pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
in the `CIBW_BEFORE_BUILD` step. Please compare with the
solutions e.g. in astropy or matplotlib for how to make this
conditional for nightly wheel builds using expressions.
If you do not worry about using pre-releases of all
dependencies, you can also use `--pre --extra-index-url` in the
build frontend (instead of build isolation).
This will become unnecessary as soon as NumPy 2.0 is released.
If your dependencies have the issue, check whether they
have nightly wheels build against NumPy 2.0.
pybind11 note: You may see this message if using pybind11,
this is not problematic at pre-release time
it indicates the need for a new pybind11 release.
After that message, the offending code may yield an exception (happens for, e.g., Matplotlib) or silently continue like nothing else happened (happens for, e.g., Dask). The latter is especially confusing - some dependency of Dask is using pybind11
, but it's not even possible to see which one (dask
itself is pure Python).
Once numpy 2.0.0rc1
appears on PyPI, a lot more users are going to see the above message and be confused, or come to this issue tracker. The frequency will go up both because a lot of packages use --pre
in their CI and because the numpy team will strongly encourage users to test that RC. A new release containing gh-4857 soon would be very helpful.
EDIT: additional reason: other libraries need to release new versions with wheels that work with numpy 2.0 - and if there's no new pybind11
release by then, it looks like they have to use pybind11
for their next releases. That's really undesirable.
Reproducible example code
This issue can be reproduced with for example a new environment in which one installs the latest `matplotlib` release from PyPI plus a `numpy` nightly:
$ mamba create -n pybind11-check python=3.11
$ mamba activate pybind11-check
$ pip install matplotlib
$ pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy -U
$ python -c "import matplotlib
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0.dev0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled against NumPy 2.0.
...
pybind11 note: You may see this message if using pybind11,
this is not problematic at pre-release time
it indicates the need for a new pybind11 release.
...
As soon as numpy `2.0.0rc1` appears on PyPI, the reproducer will be simpler: `pip install numpy matplotlib --pre` is all it would take.
Is this a regression? Put the last known working version here if it is.
Not a regression