ImportError: No module named _sqlite3

问题:在python下无法使用sqlite3,该python2.7.14 是解压 连接的
pi@dueros-python-client:/usr/local/python2.7.14 $ python
Python 2.7.14 (default, Oct 24 2017, 14:44:28)
[GCC 4.9.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import sqlite3
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/python2.7.14/lib/python2.7/sqlite3/init.py”, line 24, in
from dbapi2 import *
File “/usr/local/python2.7.14/lib/python2.7/sqlite3/dbapi2.py”, line 28, in
from _sqlite3 import *
ImportError: No module named _sqlite3

而使用python2.7,sqlite3可以使用:
pi@dueros-python-client:/ $ python2.7
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import sqlite3

同时在python3中,sqlite3也可以使用:
pi@dueros-python-client:/ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import sqlite3

因此从2.7的python库中拷贝sqlite3动态库到2.7.14中
sudo find / -name _sqlite3*.so
/usr/lib/python2.7/lib-dynload/_sqlite3.arm-linux-gnueabihf.so
/usr/lib/python3.5/lib-dynload/_sqlite3.cpython-35m-arm-linux-gnueabihf.so
/usr/lib/pypy/lib_pypy/_sqlite3_cffi.pypy-41-arm-linux-gnueabihf.so
将_sqlite3.arm-linux-gnueabihf.so 拷贝到2.7.14中
sudo cp /usr/lib/python2.7/lib-dynload/_sqlite3.arm-linux-gnueabihf.so /usr/local/python2.7.14/lib/python2.7/lib-dynload/
但是仍然报上面的错误,查看/usr/local/python2.7.14/lib/python2.7/lib-dynload $目录下的动态库,
在这里插入图片描述
动态库的名字都是名字.so,因此将_sqlite3.arm-linux-gnueabihf.so 修改成_sqlite3.so
pi@dueros-python-client:/usr/local/python2.7.14/lib/python2.7/lib-dynload $ sudo mv _sqlite3.arm-linux- gnueabihf.so _sqlite3.so
验证:问题解决
pi@dueros-python-client:/usr/local/python2.7.14/lib/python2.7/lib-dynload $ python
Python 2.7.14 (default, Oct 24 2017, 14:44:28)
[GCC 4.9.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import sqlite3

参考:https://www.cnblogs.com/saolv/p/7041067.html
https://blog.csdn.net/jaket5219999/article/details/53512071

你可能感兴趣的:(树莓派)