Théo Vermersch
Théo Vermersch

Reputation: 184

No module named '_sqlite3' Python 3.7.5 Centos 7

I'm trying to use sqlite3 with Python3.7.5 on a Centos 7 system.

With

python3.7 -c "import sqlite3;print(sqlite3.version)"

I got the following

Traceback (most recent call last):
  File "<string>", 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'

So I try to re-installed Python from sources with:

yum install -y gcc make sqlite-devel zlib-devel libffi-devel openssl-devel wget 

wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar xzf Python-3.7.5.tgz
cd Python-3.7.5
sudo ./configure --enable-optimizations --enable-loadable-sqlite-extensions
sudo make
sudo make altinstall  

But even with both sqlite-devel and --enable-loadable-sqlite-extensions I still have the same issue

NB1:

Followings

ll /usr/local/lib/python3.7/lib-dynload/ | grep sqlite
-rwxr-xr-x. 1 root root  311272 Jan  6 11:49 _sqlite3.cpython-37m-x86_64-linux-gnu.so

and

ll /usr/local/lib/python3.7/sqlite3/
total 16
-rw-r--r--. 1 root root 2687 Jan  6 11:50 dbapi2.py
-rw-r--r--. 1 root root 2825 Jan  6 11:50 dump.py
-rw-r--r--. 1 root root 1018 Jan  6 11:50 __init__.py
drwxr-xr-x. 2 root root 4096 Jan  6 11:51 __pycache__
drwxr-xr-x. 3 root root  210 Jan  6 11:50 test

are existing

NB2: While experimenting the same commands on a Docker container from scratch, sqlite3 works perfectly

FROM centos:7

RUN yum update -y && \
    yum install -y \
    gcc make sqlite-devel zlib-devel libffi-devel openssl-devel wget 

RUN wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz && \
    tar xzf Python-3.7.5.tgz && \
    cd Python-3.7.5 && \
    ./configure --enable-optimizations --enable-loadable-sqlite-extensions && \
    make altinstall && \
    cd .. && \
    rm -Rf Python-3.7.5 && \
    rm -f Python-3.7.5.tgz

Did i miss something ?

Upvotes: 2

Views: 9678

Answers (1)

Th&#233;o Vermersch
Th&#233;o Vermersch

Reputation: 184

So I finally find a fix:

I delete all the python binaries and linked files/folders from /usr/local/bin the I have delete /usr/local/lib/python3.7.

The I have re-install Python from sources and now SQLite works like a charm.

I think I must have issue with relicate of previous Python installation.

Upvotes: 1

Related Questions