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 <module>
    from . import multiarray
  File "/opt/conda/lib/python3.8/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/opt/conda/lib/python3.8/site-packages/numpy/core/overrides.py", line 6, in <module>
    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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值