9

I'm using Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 on my Debian, and I'm usually using module sqlite3 without any problem.

I compiled a Sqlite extension spellfix, I get this error when loading it:

sqlite3.OperationalError: ./spellfix.so: undefined symbol: sqlite3_malloc64

I think it might be because the sqlite3 module is too old:

import sqlite3
print sqlite3.version          # 2.6.0
print sqlite3.sqlite_version   # 3.8.2

(On another machine where sqlite3.sqlite_version is 3.8.7.x the extension loads fine).

I tried:

pip install --upgrade pysqlite

but it's still the same: sqlite3.sqlite_version stays 3.8.2.

How to upgrade the Python sqlite3 module (which is built-in in the standard library)?

Basj
  • 41,386
  • 99
  • 383
  • 673
  • Sidenote: I already tried this (specific for Mac), and tried to adapt it without any success: https://stackoverflow.com/q/26345972/1422096 – Basj Apr 13 '18 at 15:52
  • Is it a duplicate of [this question](https://stackoverflow.com/q/49053285/2072035)? – saaj Apr 20 '18 at 09:39

2 Answers2

5

You are right in thinking that the version of sqlite3 causes the problem. sqlite_malloc64 was introduced with release 3.8.7.

Instead of trying to upgrade the Python sqlite3 module which may end up breaking your Python installation, I would suggest compiling the version of spellfix.c included with version 3.8.2.

You can find the source here: https://www.sqlite.org/src/tarball/27392118/SQLite-27392118.tar.gz

From there you can build the amalgamation with:

sh configure
make sqlite3.c

You will have sqlite3.h and sqlite3ext.h in the tsrc folder. Then compile the spellfix.c extension with:

gcc -g -fPIC -shared spellfix.c -I ../../tsrc -o spellfix.dll

And you should get a compatible spellfix.dll that runs with your version of sqlite3.

Jacques Gaudin
  • 15,779
  • 10
  • 54
  • 75
  • Thanks a lot. Isn't there 2 links similar to https://sqlite.org/2016/sqlite-src-3110100.zip and https://sqlite.org/2016/sqlite-amalgamation-3110100.zip that I could use? So I could reuse directly this: https://stackoverflow.com/a/49815419/1422096 – Basj Apr 15 '18 at 22:42
  • I have been looking for them but I was only able to find the source of 3.8.2. I will double-check when I have some time. Hopefully the above should get you up and running although it is not exactly answering your question on how to upgrade `sqlite3`! – Jacques Gaudin Apr 15 '18 at 22:45
  • 1
    Thanks a lot again! Now this [recipe](https://stackoverflow.com/a/49815419/1422096) is rather complete :) – Basj Apr 16 '18 at 07:52
  • Out of curiosity, why are you using a 2014 OS? – Jacques Gaudin Apr 18 '18 at 15:02
  • You're right, about this it's 100% my fault, and probably a bad use of *If it ain't broke, don't fix it* ;) Another real reason is that I would need another server to handle the temporary reinstall etc. – Basj Apr 18 '18 at 15:05
2

Here is a manual solution (NOT RECOMMENDED, but as I didn't find backports for libsqlite3 v3.23.1 for my Linux install, I tried this, and it worked):

  1. Download from https://packages.debian.org/search?keywords=libsqlite3-0 a newer version. Here is a direct link:

    wget http://ftp.de.debian.org/debian/pool/main/s/sqlite3/libsqlite3-0_3.23.1-1_amd64.deb
    
  2. Decompress the .deb in a temporary folder:

    mkdir tmp
    dpkg -x libsqlite3-0_3.23.1-1_amd64.deb tmp
    

    or

    mkdir tmp; cd tmp; ar x ../libsqlite3-0_3.23.1-1_amd64.deb; tar xvfJ data.tar.xz; cd ..
    

    then

    # keep the old one in case it wouldn't work!
    mv /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6.old   
    
    # copy the new one in the right place
    cp tmp/usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6
    
  3. It should work:

    python -c "import sqlite3; print sqlite3.sqlite_version"   # 3.23.1
    

Disclaimer: this is a bit hack-ish, but it works.

Basj
  • 41,386
  • 99
  • 383
  • 673
  • 1
    Hack-ish indeed. I attempted this to update sqlite from 3.34 to 3.37 and ran into other version dependencies. Ultimately I decided it wasn't worth the effort. Thank you though! – JosiahDub Feb 10 '22 at 21:33