python SOABI兼容性问题

首先说明一点:龙芯发布的仓库都是基于configure.ac 中包含loongarch64-linux-gnu定义的python所构建

https://blog.csdn.net/zhangna20151015/article/details/128807969?spm=1001.2014.3001.5502 (包含龙芯自己搭建的pypi仓库)

  1. 问题现象

模块明明已经安装到正确的路径下,但是报模块找不到的情况。ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

[root@adc50b6236aa build-shared]# python3 -c "import numpy" 
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/numpy/core/__init__.py", line 23, in 
    from . import multiarray
  File "/opt/conda/lib/python3.8/site-packages/numpy/core/multiarray.py", line 10, in 
    from . import overrides
  File "/opt/conda/lib/python3.8/site-packages/numpy/core/overrides.py", line 6, in 
    from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

2.问题原因

1. configure.ac中不加mulitiarch 部分,./confiure输出

checking SOABI... cpython-38

2. configure.ac中添加mulitiarch部分, ./confiure输出

checking SOABI... cpython-38-loongarch64-linux-gnu

总结:SOABI的问题

2.1 手动构建python

./configure && make

[root@adc50b6236aa numpy]# python3
Python 3.8.6 (tags/v3.8.6-dirty:db455296be, Nov  1 2022, 12:18:24) 
[GCC 8.3.0 20190222 (Loongson 8.3.0-31 vec)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib.machinery
>>> print(importlib.machinery.all_suffixes())
['.py', '.pyc', '.cpython-38.so', '.abi3.so', '.so']
>>> 

2.2 手动如下方式构建python

修改configure.ac/configure.in,增加LA的支持 ##参考代码:https://github.com/python/cpython/pull/30939/files

autoconf ## 重新生成configure

autoheader

./configure && make

[root@adc50b6236aa lib]# python3 -c "import numpy" 
[root@adc50b6236aa cpython-1.orj]# python3         
Python 3.8.6 (tags/v3.8.6-dirty:db455296be, Nov  2 2022, 06:50:38) 
[GCC 8.3.0 20190222 (Loongson 8.3.0-31 vec)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/opt/conda/lib/python38.zip', '/opt/conda/lib/python3.8', '/opt/conda/lib/python3.8/lib-dynload', '/root/.local/lib/python3.8/site-packages', '/opt/conda/lib/python3.8/site-packages']
SyntaxError: invalid syntax
>>> import importlib.machinery
>>> print(importlib.machinery.all_suffixes())
['.py', '.pyc', '.cpython-38-loongarch64-linux-gnu.so', '.abi3.so', '.so']
>>> import numpy
>>> 

3. 解决方案

修改configure.ac/configure.in,增加LA的支持

autoconf ## 重新生成configure

autoheader

./configure && make

4. 查看

方式一:importlib.machinery.all_suffixes()进行查看

方式二:python3-config --extension-suffix

[loongson@localhost ~]$ python3-config --extension-suffix

.cpython-38-loongarch64-linux-gnu.so

你可能感兴趣的:(LoongArch,python,python,开发语言,loongarch,导入numpy报错)