8

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.

asked Jun 22, 2020 at 20:43
4
  • Does this answer your question? Python sqlite3: run different sqlite3 version Commented Jun 22, 2020 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. Commented Jun 22, 2020 at 20:55
  • @Xeoth Did I answer your question? Commented Jun 23, 2020 at 9: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]. Commented Jun 23, 2020 at 14:10

4 Answers 4

10

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'
answered May 19, 2021 at 9:17
Sign up to request clarification or add additional context in comments.

1 Comment

After 8hrs of effort this export LD_LIBRARY_PATH="/usr/local/lib" helped me, thanks
2

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.

answered Jun 23, 2020 at 8:21

Comments

0

Rather than use sqlite's installation defaults to overwrite the system /usr/bin/sqlite3, and for which will be overwritten by yum updates, instead, make use of /usr/local/bin which for most will be further up on the PATH than /usr/bin (if it's not in your case, then make use of some other directory that is and use that in the below steps). Furthermore, this ties in nicely with /usr/local/lib64 for dynamic libs.

# One time setup -- Change to preference
echo "/usr/local/lib64" | sudo tee /etc/ld.so.conf.d/local-lib64.conf
# SQLite3 Upgrade steps
## Build
curl https://www.sqlite.org/2024/sqlite-autoconf-3460100.tar.gz | tar xzf -
cd sqlite-autoconf-3460100
./configure --prefix=/usr/local --libdir=/usr/local/lib64
make
## Install
sudo make install
libtool --finish /usr/local/lib64
sudo ldconfig
hash -r
## Verify
sqlite3 -version
# > 3.46.1 2024年08月13日 09:16:08 c9c2ab54ba1f5f46360f1b4f35d849cd3f080e6fc2b6c60e91b16c63f69a1e33 (64-bit)
ldconfig -p | grep sqlite # newer libs at /usr/local/lib64
# > libsqlite3.so.0 (libc6,x86-64) => /usr/local/lib64/libsqlite3.so.0
# > libsqlite3.so.0 (libc6,x86-64) => /lib64/libsqlite3.so.0
# > libsqlite3.so (libc6,x86-64) => /usr/local/lib64/libsqlite3.so
# > libsqlite3.so (libc6,x86-64) => /lib64/libsqlite3.so
python3 -c 'import sqlite3; print(sqlite3.sqlite_version)'
# > 3.46.1
answered Sep 19, 2024 at 21:33

Comments

0

If you use conda, you can choose a specific version with libsqlite, for instance libsqlite==3.46.1. Please note that libsqlite is available only in conda.

answered Feb 20, 2025 at 15:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.