ModuleNotFoundError: No module named ‘_sqlite3‘
原因:python3.11是通过源码手动安装的,而系统自带的是python3.10,所以sudo apt install python3-dev命令是默认把sqlite扩展安装到python3.10下的,于是就导致3.11版本的缺少对应的.so文件。3. 把python3.10的so文件复制到3.11的动态库里并修改版本号(把so文件名里的310改成311)解决:把3.10的_sqlite3.xx
Raspberry Pi 3B+ 服务器debian 11系统,安装python3.11.5之后,执行sqlite3相关的单元测试时,报错如下:
Following modules built successfully but were removed because they could not be imported: _sqlite3
*** 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
The necessary bits to build these optional modules were not found:
_lzma
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Following modules built successfully but were removed because they could not be imported:
_sqlite3
Following modules built successfully but were removed because they could not be imported:
_sqlite3
running build_scripts
creating build/scripts-3.11
copying and adjusting /root/Python-3.11.5/Tools/scripts/pydoc3 -> build/scripts-3.11
copying and adjusting /root/Python-3.11.5/Tools/scripts/idle3 -> build/scripts-3.11
copying and adjusting /root/Python-3.11.5/Tools/scripts/2to3 -> build/scripts-3.11
changing mode of build/scripts-3.11/pydoc3 from 644 to 755
changing mode of build/scripts-3.11/idle3 from 644 to 755
changing mode of build/scripts-3.11/2to3 from 644 to 755
renaming build/scripts-3.11/pydoc3 to build/scripts-3.11/pydoc3.11
renaming build/scripts-3.11/idle3 to build/scripts-3.11/idle3.11
renaming build/scripts-3.11/2to3 to build/scripts-3.11/2to3-3.11
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__)'
我的输出为:
root@raspberrypi:~# python3.10 -c 'import _sqlite3 as m;print(m.__file__)'
/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__)'
更多推荐
所有评论(0)