2

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 ?

Théo Vermersch
  • 164
  • 1
  • 9
  • Does this answer your question? [No module named \_sqlite3](https://stackoverflow.com/questions/1210664/no-module-named-sqlite3) – kendriu Jan 06 '20 at 17:28
  • Not really i try severals others solution like copying the sqlite .so manually into Python libs: `cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.7/sqlite3/` and `cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.7/lib-dynload/` but it still not work – Théo Vermersch Jan 07 '20 at 08:41
  • I have also try to `rm -Rf /usr/local/lib/python3.7/` and to re-install from sources but it still not working – Théo Vermersch Jan 07 '20 at 09:03

1 Answers1

1

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.

Théo Vermersch
  • 164
  • 1
  • 9