Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d271d5

Browse files
authored
Merge pull request#29036 from seberg/cmodule-import-info
DOC: Expand/clean up extension module import error
2 parents27aac15 +ae01519 commit1d271d5

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

‎numpy/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@
111111
try:
112112
fromnumpy.__config__importshow_config
113113
exceptImportErrorase:
114-
msg="""Error importing numpy: you should not try to import numpy from
115-
its source directory; please exit the numpy source tree, and relaunch
116-
your python interpreter from there."""
117-
raiseImportError(msg)frome
114+
ifisinstance(e,ModuleNotFoundError)ande.name=="numpy.__config__":
115+
# The __config__ module itself was not found, so add this info:
116+
msg="""Error importing numpy: you should not try to import numpy from
117+
its source directory; please exit the numpy source tree, and relaunch
118+
your python interpreter from there."""
119+
raiseImportError(msg)frome
120+
raise
118121

119122
from .import_core
120123
from ._coreimport (

‎numpy/_core/__init__.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,60 @@
2222
from .importmultiarray
2323
exceptImportErrorasexc:
2424
importsys
25-
msg="""
25+
26+
# Basically always, the problem should be that the C module is wrong/missing...
27+
if (
28+
isinstance(exc,ModuleNotFoundError)
29+
andexc.name=="numpy._core._multiarray_umath"
30+
):
31+
importsys
32+
candidates= []
33+
forpathin__path__:
34+
candidates.extend(
35+
fforfinos.listdir(path)iff.startswith("_multiarray_umath"))
36+
iflen(candidates)==0:
37+
bad_c_module_info= (
38+
"We found no compiled module, did NumPy build successfully?\n")
39+
else:
40+
candidate_str='\n * '.join(candidates)
41+
# cache_tag is documented to be possibly None, so just use name if it is
42+
# this guesses at cache_tag being the same as the extension module scheme
43+
tag=sys.implementation.cache_tagorsys.implementation.name
44+
bad_c_module_info= (
45+
f"The following compiled module files exist, but seem incompatible\n"
46+
f"with with either python '{tag}' or the "
47+
f"platform '{sys.platform}':\n\n *{candidate_str}\n"
48+
)
49+
else:
50+
bad_c_module_info=""
51+
52+
major,minor,*_=sys.version_info
53+
msg=f"""
2654
2755
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
2856
2957
Importing the numpy C-extensions failed. This error can happen for
3058
many reasons, often due to issues with your setup or how NumPy was
3159
installed.
32-
60+
{bad_c_module_info}
3361
We have compiled some common reasons and troubleshooting tips at:
3462
3563
https://numpy.org/devdocs/user/troubleshooting-importerror.html
3664
3765
Please note and check the following:
3866
39-
* The Python version is: Python%d.%d from "%s"
40-
* The NumPy version is: "%s"
67+
* The Python version is: Python{major}.{minor} from "{sys.executable}"
68+
* The NumPy version is: "{__version__}"
4169
4270
and make sure that they are the versions you expect.
43-
Please carefully study the documentation linked above for further help.
4471
45-
Original error was: %s
46-
"""% (sys.version_info[0],sys.version_info[1],sys.executable,
47-
__version__,exc)
72+
Please carefully study the information and documentation linked above.
73+
This is unlikely to be a NumPy issue but will be caused by a bad install
74+
or environment on your machine.
75+
76+
Original error was:{exc}
77+
"""
78+
4879
raiseImportError(msg)fromexc
4980
finally:
5081
forenvkeyinenv_added:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp