4

I have Python 3.8 installed alongside SQLite 3.16.2 on Debian 9.12 and I need to upgrade to a newer version of SQLite. I've downloaded and compiled the amalgamation available on the SQLite's site, and put it in /usr/bin, so when I do

$ sqlite3 --version

I get 3.32.3 in response (which is the version I compiled).

However, when I do

$ python3.8
>>> import sqlite3
>>> sqlite3.sqlite_version

I get 3.16.2, which is the earlier version. How do I change the SQLite version picked up by Python?

mkrieger1 suggested that this question may answer mine. It won't work here, as the solution provided there is directed at Python 2, not Python 3. pysqlite2 does not work with Python 3.

Xeoth
  • 1,285
  • 1
  • 11
  • 22
  • Does this answer your question? [Python sqlite3: run different sqlite3 version](https://stackoverflow.com/questions/29282380/python-sqlite3-run-different-sqlite3-version) – mkrieger1 Jun 22 '20 at 20:46
  • That answer is provided for Python 2, and I'm working with Python 3. `pysqlite2` does not work with Python 3, unfortunately. – Xeoth Jun 22 '20 at 20:55
  • @Xeoth Did I answer your question? – Eno Gerguri Jun 23 '20 at 09:38
  • Do you really need it? It could break some assumption on other python standard lib modules. I think you can recompile Python with the version you want [and check with the test in Python source if it is safe to do so]. – Giacomo Catenazzi Jun 23 '20 at 14:10

2 Answers2

5

In my case I cannot replace with newer version because I cannot find these files. (I installed the sqlite-autoconf-3350500)

I used another manner to let it work just execute below command

export LD_LIBRARY_PATH="/usr/local/lib"

>>> import sqlite3
>>> sqlite3.sqlite_version
'3.35.5'
zhuguowei
  • 8,401
  • 16
  • 70
  • 106
1

The way I would go around it, is by finding out the path to the old sqlite version that you are importing:

import sqlite3
print(sqlite3.__file__)

For me, this outputs:

C:\Users\YOUR_USERNAME_HERE\AppData\Local\Programs\Python\Python38\lib\sqlite3\__init__.py

Go to the lib path:

C:\Users\YOUR_USERNAME_HERE\AppData\Local\Programs\Python\Python38\lib

Then find the sqlite3 folder and delete it, then replace it with your up-to-date version. Re-try:

>>> import sqlite3
>>> sqlite3.sqlite_version

You should get your new version.

Eno Gerguri
  • 639
  • 5
  • 22