@@ -14,50 +14,34 @@ def __getattr__(attr_name):
14
14
from ._utils import _raise_warning
15
15
16
16
if attr_name in {"_ARRAY_API" , "_UFUNC_API" }:
17
- from numpy .version import short_version , release
17
+ from numpy .version import short_version
18
18
import textwrap
19
19
import traceback
20
20
import sys
21
21
22
22
msg = textwrap .dedent (f"""
23
23
A module that was compiled using NumPy 1.x cannot be run in
24
24
NumPy { short_version } as it may crash. To support both 1.x and 2.x
25
- versions of NumPy, modules must be compiled against NumPy 2.0.
25
+ versions of NumPy, modules must be compiled with NumPy 2.0.
26
+ Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
26
27
27
28
If you are a user of the module, the easiest solution will be to
28
- either downgrade NumPy or update the failing module (if available).
29
+ downgrade to 'numpy<2' or try to upgrade the affected module.
30
+ We expect that some modules will need time to support NumPy 2.
29
31
30
32
""" )
31
- if not release and short_version .startswith ("2.0.0" ):
32
- # TODO: Can remove this after the release.
33
- msg += textwrap .dedent ("""\
34
- NOTE: When testing against pre-release versions of NumPy 2.0
35
- or building nightly wheels for it, it is necessary to ensure
36
- the NumPy pre-release is used at build time.
37
- The main way to ensure this is using no build isolation
38
- and installing dependencies manually with NumPy.
39
-
40
- If your dependencies have the issue, check whether they
41
- build nightly wheels build against NumPy 2.0.
42
-
43
- pybind11 note: If you see this message and do not see
44
- any errors raised, it's possible this is due to a
45
- package using an old version of pybind11 that should be
46
- updated.
47
-
48
- """ )
49
- msg += "Traceback (most recent call last):"
33
+ tb_msg = "Traceback (most recent call last):"
50
34
for line in traceback .format_stack ()[:- 1 ]:
51
35
if "frozen importlib" in line :
52
36
continue
53
- msg += line
54
- # Only print the message. This has two reasons (for now!):
55
- # 1. Old NumPy replaced the error here making it never actually show
56
- # in practice, thus raising alone would not be helpful.
57
- # 2. pybind11 simply reaches into NumPy internals and requires a
58
- # new release that includes the fix. That is missing as of 2023-11 .
59
- # But, it "conveniently" ignores the ABI version.
60
- sys . stderr . write (msg )
37
+ tb_msg += line
38
+
39
+ # Also print the message (with traceback). This is because old versions
40
+ # of NumPy unfortunately set up the import to replace (and hide) the
41
+ # error. The traceback shouldn't be needed, but e.g. pytest plugins
42
+ # seem to swallow it and we should be failing anyway.. .
43
+ sys . stderr . write ( msg + tb_msg )
44
+ raise ImportError (msg )
61
45
62
46
ret = getattr (_multiarray_umath , attr_name , None )
63
47
if ret is None :
0 commit comments