python / python/cpython

Improve import error when extension module is an incompatible build

未關閉
#134,493 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

interpreter-core topic-C-API topic-importlib type-feature
主要語言
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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

該 issue 沒有指出原始檔案、測試或進入點。首先確定該診斷屬於 Python 的擴充模組匯入處理,還是屬於 NumPy,然後定義應如何識別不相容的檔案名稱或架構。完成的標準是:不相容的擴充模組能產生一則簡潔且可採取行動的訊息,顯示相關的預期與實際 build 詳細資訊。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。