英文:
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 "
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论