ModuleNotFoundError: ไม่มีโมดูลชื่อ '_sqlite3'

Sep 23 2020

เรามีเวอร์ชัน python ที่แตกต่างกันติดตั้งและใช้งานโดยเฉพาะpython3.7ดังนั้นฉันจึงแก้ไข.bashrcไฟล์ของฉัน เราใช้Centos7กับLinuxเซิร์ฟเวอร์

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
alias python=python3.7
alias pip=pip3.7


[xyz@innolx20122 ~]$ python
python             python2.7          python3.6          python3.7          python3.7m-config
python2            python3            python3.6m         python3.7m

[xyz@innolx20122 ~]$ which sqlite3
/usr/bin/sqlite3

การทำงานของตนด้วยpython2.7และpython3.6รุ่น

[xyz@innolx20122 ~]$ python2.7
Python 2.7.5 (default, Apr  2 2020, 13:16:51)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3

[xyz@innolx20122 ~]$ python3.6
Python 3.6.8 (default, Apr  2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3

มันไม่ทำงานกับpython3.7เวอร์ชัน

[xyz@innolx20122 ~]$ python3.7
Python 3.7.0 (default, Sep  3 2020, 09:25:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

อัปเดต -

เราติดตั้ง python ตามคำแนะนำในลิงค์ด้านล่างลิงค์ การติดตั้ง Python3.7

ดังนั้นpython3.7เวอร์ชันของฉันจึงถูกติดตั้งที่ระดับรูท

[root@innolx20122 ~]# ls
anaconda-ks.cfg  Python-3.7.0  Python-3.7.0.tgz
[root@innolx20122 ~]# cd Python-3.7.0
[root@innolx20122 Python-3.7.0]# ls
aclocal.m4    config.status  Doc         Lib              Mac              Misc     PC              pyconfig.h     python-config     setup.py
build         config.sub     Grammar     libpython3.7m.a  Makefile         Modules  PCbuild         pyconfig.h.in  python-config.py  Tools
config.guess  configure      Include     LICENSE          Makefile.pre     Objects  Programs        python         python-gdb.py
config.log    configure.ac   install-sh  m4               Makefile.pre.in  Parser   pybuilddir.txt  Python         README.rst

ฉันเห็นลิงก์หนึ่งในสแต็กโอเวอร์โฟลว์แนะนำวิธีแก้ปัญหาบางอย่าง แก้ไขปัญหา Sqlite3

กรุณาแนะนำว่าสามารถเรียกใช้คำสั่งด้านล่างจากไดเรกทอรีรากเดียวกันได้หรือไม่

yum install sqlite-devel

./configure
make && make altinstall

คำตอบ

1 vikrantrana Sep 27 2020 at 05:58

ฉันเข้าสู่ระบบในฐานะrootผู้ใช้

[root@innolx20122 ~]# ls
anaconda-ks.cfg  Python-3.7.0  Python-3.7.0.tgz

จากนั้นไปที่Python-3.7.0ไดเร็กทอรี

[root@innolx20122 Python-3.7.0]# ls
aclocal.m4    config.status  Doc         Lib              Mac              Misc     PC              pyconfig.h     python-config     setup.py
build         config.sub     Grammar     libpython3.7m.a  Makefile         Modules  PCbuild         pyconfig.h.in  python-config.py  Tools
config.guess  configure      Include     LICENSE          Makefile.pre     Objects  Programs        python         python-gdb.py
config.log    configure.ac   install-sh  m4               Makefile.pre.in  Parser   pybuilddir.txt  Python         README.rst

หลังจากนั้นเรียกใช้คำสั่งด้านล่างเพื่อแก้ไขปัญหา

yum install sqlite-devel

./configure
make && make altinstall


[xyz@innolx20122 ~]$ python3.7
Python 3.7.0 (default, Sep 26 2020, 23:18:27)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>>