@@ -148,67 +148,74 @@ This may mainly help you if you are not running the python and/or NumPy
148
148
version you are expecting to run.
149
149
150
150
151
- C-API incompatibility
152
- ---------------------------
151
+ Downstream ImportError, AttributeError or C-API/ABI incompatibility
152
+ ===================================================================
153
153
154
- If you see an error like :
154
+ If you see a message such as: :
155
155
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'.
156
160
157
- RuntimeError: module compiled against API version v1 but this version of numpy is v2
161
+ either as an `` ImportError `` or with::
158
162
163
+ AttributeError: _ARRAY_API not found
159
164
160
- You may have :
165
+ or other errors such as: :
161
166
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
165
168
166
- * An environment issue messing with package versions.
169
+ or when a package implemented with Cython::
167
170
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
169
172
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' ``.
172
177
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.
175
182
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:
179
184
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.)
182
187
188
+ * You have version constraints and ``pip `` may
189
+ have installed a combination of incompatible packages.
183
190
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).
185
193
194
+ The best solution will usually be to upgrade the failing package:
186
195
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 ``.
189
198
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.
191
202
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.
196
205
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:
198
208
199
- AttributeError: _ARRAY_API not found
209
+ * Install a compatible NumPy version:
200
210
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 ``.
204
215
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.
209
218
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.
212
219
213
220
214
221
Segfaults or crashes
0 commit comments