• ModuleNotFoundError: No module named ‘_sqlite3‘


    Raspberry Pi 3B+ 服务器debian 11系统,安装python3.11.5之后,执行sqlite3相关的单元测试时,报错如下:

    Following modules built successfully but were removed because they could not be imported:
    _sqlite3  
    1. *** WARNING: renaming "_sqlite3" since importing it failed: /root/Python-3.11.5/build/lib.linux-armv7l-3.11/_sqlite3.cpython-311-arm-linux-gnueabihf.so: undefined symbol: sqlite3_deserialize
    2. The necessary bits to build these optional modules were not found:
    3. _lzma
    4. To find the necessary bits, look in setup.py in detect_modules() for the module's name.
    5. Following modules built successfully but were removed because they could not be imported:
    6. _sqlite3
    7. Following modules built successfully but were removed because they could not be imported:
    8. _sqlite3
    9. running build_scripts
    10. creating build/scripts-3.11
    11. copying and adjusting /root/Python-3.11.5/Tools/scripts/pydoc3 -> build/scripts-3.11
    12. copying and adjusting /root/Python-3.11.5/Tools/scripts/idle3 -> build/scripts-3.11
    13. copying and adjusting /root/Python-3.11.5/Tools/scripts/2to3 -> build/scripts-3.11
    14. changing mode of build/scripts-3.11/pydoc3 from 644 to 755
    15. changing mode of build/scripts-3.11/idle3 from 644 to 755
    16. changing mode of build/scripts-3.11/2to3 from 644 to 755
    17. renaming build/scripts-3.11/pydoc3 to build/scripts-3.11/pydoc3.11
    18. renaming build/scripts-3.11/idle3 to build/scripts-3.11/idle3.11
    19. renaming build/scripts-3.11/2to3 to build/scripts-3.11/2to3-3.11
    20. root@raspberrypi:~/Python-3.11.5#


    原因

    python3.11.5是通过源码手动安装的,而系统自带的是python3.10,所以sudo apt install python3-dev命令是默认把sqlite扩展安装到python3.10下的,于是就导致3.11版本的缺少对应的.so文件

    Solution:

    把3.10的_sqlite3.xxx.so文件复制到3.11的动态库里

    具体命令如下:

    1. 展示python3.10的sqlite3模块的so文件路径

    python3.10 -c 'import _sqlite3 as m;print(m.__file__)'
    我的输出为:

    1. root@raspberrypi:~# python3.10 -c 'import _sqlite3 as m;print(m.__file__)'
    2. /usr/local/lib/python3.10/lib-dynload/_sqlite3.cpython-310-arm-linux-gnueabihf.so

    2. 找出python3.11的动态库路径

    python3.11 -c 'import random as m;print(m.__file__)'
    我的输出为:

    /usr/local/lib/python3.11/random.py

    3. 把python3.10的so文件复制到3.11的动态库里并修改版本号(把so文件名里的310改成311)

    sudo cp /usr/local/lib/python3.10/lib-dynload/_sqlite3.cpython-310-arm-linux-gnueabihf.so /root/Python-3.11.5/build/lib.linux-armv7l-3.11/_sqlite3.cpython-311-arm-linux-gnueabihf.so


    复制之后,验证效果:python3.11 -c 'import _sqlite3 as m;print(m.__file__)'
     

  • 相关阅读:
    JVM理解(三)
    详解HTTP1.0、1.1、2.0版本区别/优化
    【示波器专题】数字示波器的主要指标——采样率
    7、Tomcat & Servlet
    IS31FL3737B 通用12×12 LED驱动器 I2C 42mA 40QFN
    【Java面试】说一下你对CompletableFuture的理解
    鲲鹏开发者创享日2022:鲲鹏全栈创新 与开发者共建数字湖南
    ArcGIS中ArcMap求取点要素在栅格图像中的行列号的方法
    C 运算符
    【Pandas数据处理100例】(八十七):Pandas使用get_dummies构建哑变量
  • 原文地址:https://blog.csdn.net/freewzx2005/article/details/132892433