Skip to content

Commit 735a477

Browse files
authored
Merge pull request numpy#26717 from seberg/troubleshoot-dtype-size
DOC: Mention more error paths and try to consolidate import errors
2 parents d09eaa1 + 2ee535e commit 735a477

File tree

1 file changed

+45
-38
lines changed

1 file changed

+45
-38
lines changed

doc/source/user/troubleshooting-importerror.rst

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -148,67 +148,74 @@ This may mainly help you if you are not running the python and/or NumPy
148148
version you are expecting to run.
149149

150150

151-
C-API incompatibility
152-
---------------------------
151+
Downstream ImportError, AttributeError or C-API/ABI incompatibility
152+
===================================================================
153153

154-
If you see an error like:
154+
If you see a message such as::
155155

156+
A module that was compiled using NumPy 1.x cannot be run in
157+
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
158+
versions of NumPy, modules must be compiled with NumPy 2.0.
159+
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
156160

157-
RuntimeError: module compiled against API version v1 but this version of numpy is v2
161+
either as an ``ImportError`` or with::
158162

163+
AttributeError: _ARRAY_API not found
159164

160-
You may have:
165+
or other errors such as::
161166

162-
* A bad extension "wheel" (binary install) that should use
163-
`oldest-support-numpy <https://pypi.org/project/oldest-supported-numpy/>`_ (
164-
with manual constraints if necessary) to build their binary packages.
167+
RuntimeError: module compiled against API version v1 but this version of numpy is v2
165168

166-
* An environment issue messing with package versions.
169+
or when a package implemented with Cython::
167170

168-
* Incompatible package versions somehow enforced manually.
171+
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
169172

170-
* An extension module compiled locally against a very recent version
171-
followed by a NumPy downgrade.
173+
This means that a package depending on NumPy was build in a way that is not
174+
compatible with the NumPy version found.
175+
If this error is due to a recent upgrade to NumPy 2, the easiest solution may
176+
be to simply downgrade NumPy to ``'numpy<2'``.
172177

173-
* A compiled extension copied to a different computer with an
174-
older NumPy version.
178+
To understand the cause, search the traceback (from the back) to find the first
179+
line that isn't inside NumPy to see which package has the incompatibility.
180+
Note your NumPy version and the version of the incompatible package to
181+
help you find the best solution.
175182

176-
The best thing to do if you see this error is to contact
177-
the maintainers of the package that is causing problem
178-
so that they can solve the problem properly.
183+
There can be various reason for the incompatibility:
179184

180-
However, while you wait for a solution, a work around
181-
that usually works is to upgrade the NumPy version::
185+
* You have recently upgraded NumPy, most likely to NumPy 2, and the other
186+
module now also needs to be upgraded. (NumPy 2 was released in June 2024.)
182187

188+
* You have version constraints and ``pip`` may
189+
have installed a combination of incompatible packages.
183190

184-
pip install numpy --upgrade
191+
* You have compiled locally or have copied a compiled extension from
192+
elsewhere (which is, in general, a bad idea).
185193

194+
The best solution will usually be to upgrade the failing package:
186195

187-
Downstream ImportError or AttributeError
188-
========================================
196+
* If you installed it for example through ``pip``, try upgrading it with
197+
``pip install package_name --upgrade``.
189198

190-
If you see a message such as::
199+
* If it is your own package or it is build locally, you need recompiled
200+
for the new NumPy version (for details see :ref:`depending_on_numpy`).
201+
It may be that a reinstall of the package is sufficient to fix it.
191202

192-
A module that was compiled using NumPy 1.x cannot be run in
193-
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
194-
versions of NumPy, modules must be compiled with NumPy 2.0.
195-
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
203+
When these steps fail, you should inform the package maintainers since they
204+
probably need to make a new, compatible, release.
196205

197-
Either as an ``ImportError`` or with::
206+
However, upgrading may not always be possible because a compatible version does
207+
not yet exist or cannot be installed for other reasons. In that case:
198208

199-
AttributeError: _ARRAY_API not found
209+
* Install a compatible NumPy version:
200210

201-
Then you are using NumPy 2 together with a module that was build with NumPy 1.
202-
NumPy 2 made some changes that require rebuilding such modules to avoid
203-
possibly incorrect results or crashes.
211+
* Try downgrading NumPy with ``pip install 'numpy<2'``
212+
(NumPy 2 was released in June 2024).
213+
* If your NumPy version is old, you can try upgrading it for
214+
example with ``pip install numpy --upgrade``.
204215

205-
As the error message suggests, the easiest solution is likely to downgrade
206-
NumPy to `numpy<2`.
207-
Alternatively, you can search the traceback (from the back) to find the first
208-
line that isn't inside NumPy to see which module needs to be updated.
216+
* Add additional version pins to the failing package to help ``pip``
217+
resolve compatible versions of NumPy and the package.
209218

210-
NumPy 2 was released in the first half of 2024 and especially smaller
211-
modules downstream are expected need time to adapt and publish a new version.
212219

213220

214221
Segfaults or crashes

0 commit comments

Comments
 (0)