Improve import error when extension module is an incompatible build
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Feature or enhancement
Proposal:
Relatively regularly we get issues e.g. in NumPy because of incompatible extension module builds. (NumPy is often the first C-extension module someone loads.)
We have a long spammy message, but it includes the original error from Python:
Original error was: No module named 'numpy._core._multiarray_umath'
In this case, I had renamed the module to make it an incorrect build:
mv <snip>/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-311-darwin.so <snip>/lib/python3.11/site-packages/numpy/_core/_multiarray_umath.cpython-312-darwin.so
I think it would be great if the error could include something like:
Binary module was build for a different Python version/system: Python version is cpython-312 rather than cpython-311) or (architecture x86 but expected arm64)
That way it is far more obvious that the build (or Python version) is wrong.
(Even just listing the files found and the expected file name would be good.)
I am not sure that is desirable for Python, since you would have to see if any file looks similar to the expected module when formatting the error. So in that case I may think about doing this in NumPy (since we know for a fact the file must be there somewhere).
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
I didn't find a discussion, this seems very slightly in a similar direction, but not about an incompatible build https://github.com/python/cpython/issues/69841.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 没有指出源文件、测试或入口点。首先确定该诊断属于 Python 的扩展模块导入处理,还是属于 NumPy,然后定义应如何识别不兼容的文件名或架构。完成的标准是:不兼容的扩展能够生成一条简洁且可操作的消息,显示相关的预期和实际 build 详细信息。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100