python / python/cpython

Improve import error when extension module is an incompatible build

Aberta
#134,493 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

interpreter-core topic-C-API topic-importlib type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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.

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

A issue não indica nenhum arquivo-fonte, teste ou ponto de entrada. Primeiro determine se o diagnóstico pertence ao tratamento de importação de módulos de extensão do Python ou ao NumPy e, em seguida, defina como nomes de arquivo ou arquiteturas incompatíveis devem ser identificados. A tarefa estará concluída quando uma extensão incompatível produzir uma mensagem concisa e acionável mostrando os detalhes de build esperados e encontrados relevantes.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
backend
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.