astropy and NumPy 2 compatibility (tested)

astropy 6.0.x fails under NumPy 2 with numpy.dtype size changed when you import astropy.table, time or coordinates. astropy 6.1 to 7.1 then fail under NumPy 2.4 with AttributeError: module 'numpy' has no attribute 'in1d'. astropy 7.2.0 works. Tested below.

1. Reproduce: astropy 6.0.1 with NumPy 2

A Python 3.11 venv with astropy==6.0.1 (which pins numpy<2, so it installs 1.26.4), then numpy==2.2.6 in a second command. b1.py:

import numpy
print("numpy", numpy.__version__)
import astropy
print("astropy", astropy.__version__)
from astropy import units as u
print((3 * u.km).to(u.m))
from astropy.table import Table
print(len(Table({"a": [1, 2, 3]})), "rows")

Output, exit code 1 (paths shortened):

$ pip install "numpy==2.2.6"
$ python b1.py
numpy 2.2.6
astropy 6.0.1
3000.0 m
Traceback (most recent call last):
  File "b1.py", line 7, in <module>
    from astropy.table import Table
  File "/venv/lib/python3.11/site-packages/astropy/table/__init__.py", line 6, in <module>
    from .column import Column, ColumnInfo, MaskedColumn, StringTruncateWarning
  File "/venv/lib/python3.11/site-packages/astropy/table/column.py", line 22, in <module>
    from ._column_mixins import _ColumnGetitemShim, _MaskedColumnGetitemShim
  File "astropy/table/_column_mixins.pyx", line 1, in init astropy.table._column_mixins
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

import astropy and astropy.units still work, which is why this surprises people: only the compiled submodules fail. In the same venv, astropy.table and astropy.stats raised numpy.dtype size changed; astropy.wcs, astropy.time, astropy.coordinates and astropy.convolution raised ImportError: numpy.core.multiarray failed to import; astropy.io.fits imported fine.

2. astropy 6.1 to 7.1 with NumPy 2.4: no attribute 'in1d'

astropy 6.1.0 is the first release built for NumPy 2 (metadata numpy>=1.23), and it ran b1.py with numpy 2.3.5. But a fresh pip install astropy==6.1.0 today pulls NumPy 2.4.6, and that fails at from astropy import units:

$ pip install "astropy==6.1.0"
$ python b1.py
numpy 2.4.6
astropy 6.1.0
Traceback (most recent call last):
  File "b1.py", line 5, in <module>
    from astropy import units as u
  File "/venv/lib/python3.11/site-packages/astropy/units/__init__.py", line 13, in <module>
    from . import (
  File "/venv/lib/python3.11/site-packages/astropy/units/astrophys.py", line 10, in <module>
    from astropy.constants import si as _si
  File "/venv/lib/python3.11/site-packages/astropy/constants/__init__.py", line 27, in <module>
    from . import cgs, si
  File "/venv/lib/python3.11/site-packages/astropy/constants/cgs.py", line 7, in <module>
    from .config import codata, iaudata
  File "/venv/lib/python3.11/site-packages/astropy/constants/config.py", line 15, in <module>
    codata = importlib.import_module(".constants." + phys_version, "astropy")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/astropy/constants/codata2018.py", line 9, in <module>
    from .constant import Constant, EMConstant
  File "/venv/lib/python3.11/site-packages/astropy/constants/constant.py", line 10, in <module>
    from astropy.units.quantity import Quantity
  File "/venv/lib/python3.11/site-packages/astropy/units/quantity.py", line 38, in <module>
    from .quantity_helper import can_have_arbitrary_unit, check_output, converters_and_unit
  File "/venv/lib/python3.11/site-packages/astropy/units/quantity_helper/__init__.py", line 16, in <module>
    from . import erfa, function_helpers, helpers, scipy_special
  File "/venv/lib/python3.11/site-packages/astropy/units/quantity_helper/function_helpers.py", line 1029, in <module>
    @function_helper  # np.in1d deprecated in not NUMPY_LT_2_0.
     ^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/astropy/units/quantity_helper/function_helpers.py", line 186, in __call__
    helps = getattr(module, f.__name__)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/numpy/__init__.py", line 792, in __getattr__
    raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")
AttributeError: module 'numpy' has no attribute 'in1d'. Did you mean: 'int16'?

NumPy 2.4 removed np.in1d (deprecated since 2.0 in favour of np.isin). With numpy 2.4.6: astropy 6.1.7, 7.0.2 and 7.1.1 fail the same way; astropy 7.2.0 works.

3. Fix: upgrade astropy, or pin NumPy

$ pip install -U astropy numpy
$ python b1.py
numpy 2.4.6
astropy 8.0.2
3000.0 m
3 rows

On Python 3.11 the upgrade resolved to astropy 8.0.2 with NumPy 2.4.6. To keep an older astropy, pin to what it was built for: numpy<2 for 6.0.x, numpy<2.4 for 6.1 to 7.1.

$ pip install "numpy<2"
$ python b1.py
numpy 1.26.4
astropy 6.0.1
3000.0 m
3 rows

Restart any Jupyter kernel after changing versions. Same problem elsewhere: SciPy, PyTables, Numba. All changes: NumPy 2 breaking changes.

Frequently asked questions

Which astropy version supports NumPy 2?

astropy 6.1.0 for NumPy 2.0 to 2.3; for NumPy 2.4, astropy 7.2.0 or newer (6.1.7, 7.0.2 and 7.1.1 failed with numpy 2.4.6).

How do I fix module 'numpy' has no attribute 'in1d' in astropy?

pip install -U astropy (7.2.0+), or pin numpy<2.4.

Written with AI assistance. Measured on 2026-10-24 on Linux with Python 3.11.17: astropy 6.0.1 with numpy 1.26.4/2.2.6, astropy 6.1.0 with numpy 2.3.5/2.4.6, astropy 6.1.7, 7.0.2, 7.1.1, 7.2.0 and 8.0.2 with numpy 2.4.6. The script ran verbatim and output was pasted unedited (paths shortened). Version pins read from PyPI metadata the same day. PlainTables is our extension; astropy and NumPy are free.