7

I need to upgrade the sqlite3 version that my python 3 uses but there seems to be no clear answers and I don't understand what determines the version of sqlite3 used by python. I am running CentOS7 with python 3.6.4 installed. CentOS had sqlite version 3.7.17 installed and I upgraded this to 3.23.1 thinking python would also use this never version of sqlite.

import sqlite3
print(sqlite3.sqlite_version)

The following code still gives me 3.17. I have googled how to upgrade the version but most solutions seem to refer to pysqlite which is python 2 only. Other solutions talk about complicated compiling processes that go way over my head.

I don't understand what determines the sqlite version that python uses. Is it determined by the python version, OS installed sqlite version? I am also running python 3.6.4 on my windows PC and it says I am running 3.14.2 so it seems that the sqlite version does not depend on the python version.

What determines the sqlite version python uses? Is there not a more straight forward way to upgrade the sqlite version for python 3?

Yano
  • 71
  • 1
  • 2
  • 3
    Python doesn't use the external sqlite3 executable at all, it uses a library that is included in its own distribution. That's why the solutions talk about compiling, that's the only way you can replace it. Why do you need to do this? – Daniel Roseman Apr 19 '18 at 12:01
  • 1
    Then why does the same version of python on my CentOS and Windows machine have very different versions of sqlite3. I need the new sqlite version because the indexes I added to my database with foreign keys are not being used with the older sqlite version it seems. When I use the latest version installed on CentOS or the version that is included in with my windows python installation it does make use of my indexes. – Yano Apr 19 '18 at 12:32

2 Answers2

9

sqlite3 is kind of external library. so, you need to set external library path.

try next command

printenv LD_LIBRARY_PATH

result will be empty, if you never set before.

next command will work using installed sqlite3 for python

export LD_LIBRARY_PATH="/usr/local/lib"

then, you can execute and get correct version you installed

import sqlite3
print(sqlite3.sqlite_version)

but this method will be reset when you logout and login again. so, if you want to do regist that environment variable every time you login, you should edit /etc/profile

sudo vi /etc/profile

and add export code

export LD_LIBRARY_PATH="/usr/local/lib"

then, if you log-out and log-in again, you can see LD_LIBRARY_PATH is registered.

PYUNGHWA KIM
  • 99
  • 1
  • 3
1

In Ubuntu, you can add dqlite repository and update it using apt.

sudo add-apt-repository -y ppa:dqlite/stable
sudo apt update
sudo apt install sqlite3
korakot
  • 37,818
  • 16
  • 123
  • 144