0

My Linux machine has sqlite3 installed:

[root@airflow-xxxxx bin]# which sqlite3
/bin/sqlite3
[root@airflow-xxxxx bin]#

However there are two versions of Python on my machine; 3.6.8 and 3.9.10:

[root@airflow-xxxxx bin]# python3
Python 3.6.8 (default, Aug 13 2020, 07:46:32)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> exit()
[root@airflow-xxxxx bin]# python
Python 3.9.10 (main, Nov 21 2022, 14:02:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] 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.9/sqlite3/__init__.py", line 57, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.9/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
>>>

But only the 3.6 version recognizes installed sqlite3. I tried installing sqlite-devel but got "module not found" from Nexus. As I understand, SQLite comes bundled with Python. How do I get Python 3.9 to recognize the SQLite installed?

user4157124
  • 2,809
  • 13
  • 27
  • 42
djgcp
  • 163
  • 1
  • 14
  • Does this answer your question? [No module named \_sqlite3](https://stackoverflow.com/questions/1210664/no-module-named-sqlite3) – vencaslac Nov 22 '22 at 12:23
  • @vencaslac It did not help. A similar question - https://stackoverflow.com/questions/65336876/python3-5-sees-but-python3-9-does-not-see-sqlite3 – djgcp Nov 22 '22 at 12:33

1 Answers1

0

i actually had this problem recently, the issue is the order of installation, the _sqlite3 problem only seems to happen for versions of python 3.8 and above when python is built from source.

how were the two installations of python put on the machine? one solution would be to uninstall the 3.9 completely, (i used this answer when i had this problem https://unix.stackexchange.com/questions/190794/uninstall-python-installed-by-compiling-source) then yum install sqlite-devel and only after this is completed build python from source again as an altinstall with:

./configure --enable-optimizations --enable-loadable-sqlite-extensions

if you are unsure how to build python from source you can use this tutorial:

https://docs.posit.co/resources/install-python-source/ note that you will need to add the --enable-loadable-sqlite-extensions flag

you could also use an asnwer such as this one: https://superuser.com/questions/686980/how-to-install-alternative-version-of-python-beside-distro-supplied to create an alternate instalation

in any case, it's a real pain, i hope this helps

vencaslac
  • 2,727
  • 1
  • 18
  • 29