No module named '_sqlite3' Python 3.7.5 Centos 7

huangapple go评论77阅读模式
英文:

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 "", line 1, in
File "/usr/local/lib/python3.7/sqlite3/init.py", line 23, in
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.7/sqlite3/dbapi2.py", line 27, in
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 ?

英文:

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 ?

答案1

得分: 1

我最终找到了解决方法:

我删除了所有位于/usr/local/bin目录下的Python二进制文件和链接的文件/文件夹,然后删除了/usr/local/lib/python3.7

然后,我从源代码重新安装了Python,现在SQLite正常工作。

我认为之前的Python安装残留可能引起了问题。

英文:

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.

huangapple
  • 本文由 发表于 2020年1月7日 01:01:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616118.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定