2

I've installed Python 3.6 on a Centos 7.4 box, and need an updated version of SQLite (I'm using some new features). The SQLite version that comes with it is very old: 3.7.17.

How is this done? On Windows it's a simple matter of replacing the sqlite.dll file in the Python\DLLs directory with your desired one, but I've found nothing for how to do it on Linux.

I can see the question was asked before over on SO, but not answered - https://stackoverflow.com/questions/39064472/how-to-update-sqlite3-in-centos-6-6 - that's about the only page my googling; most of the other results are Python 2/pysqlite which don't help me.

So, how do you update the SQLite version used by Python on a CentOS box?

1

You will need to either find an RPM with the newer version or you will need to download the precompiled binaries for your OS (https://www.sqlite.org/download.html) or download source/compile/install the software.

It is normally recommend to stay with RPMs for better management of software (for installing, upgrading, etc.) though if you cannot find the RPM that will work feel free to try installing the precompiled version or compile the software and install it. This is often done on Linux systems to get the latest or a specific version of the software one needs to run certain software.

After compiling SQLite you should be able to point to the libraries for python, a quick way is to set you LD_LIBRARY_PATH to the output of lib directory you would have gotten from the compile of SQLite:

Libraries have been installed in: /usr/local/sqlite-3.22.0/lib If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the 'LD_RUN_PATH' environment variable during linking - use the '-Wl,-rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to '/etc/ld.so.conf'

If you run your python before setting your libraries you will see the old version:

python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.7.17

With the new version:

export LD_LIBRARY_PATH=/usr/local/sqlite-3.22.0/lib
python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.22.0

Depending on your environment you might need to setup this in your code or before your code gets run, depending on how you manage different versions of libraries. Though the output from the compile can give you some ideas on this.

  • Thanks. I can compile a version of sqlite (I think) - but how do I install it for Python to use? That's my biggest problem, I don't even know where to start. – linux_confusion Mar 28 '18 at 14:57
  • I did come across that, but it's Python 2 and pysqlite2; at some point it became a builtin module - called sqlite3 – linux_confusion Mar 28 '18 at 15:26
  • Can you do import sqlite3 and show the version (sqlite3.version) and the location (print (sqlite3.__file__)) – Douglas Ohlhorst Mar 28 '18 at 17:02
  • the sqlite3 module version is 2.6.0. The sqlite3 module file is at /usr/lib64/python3.6/sqlite3/__init__.py. I've managed to compile a copy of sqlite locally using the instructions from: www2.sqlite.org/cgi/src/doc/trunk/README.md - it's sitting in my Home directory. But my question remains - how do I get Python to use it? I've never grokked how Linux structures files or does that stuff. – linux_confusion Mar 29 '18 at 9:53
  • Thanks Douglas. Elsewhere a post suggested simply replacing the system sqlite3 library would be enough and Python would use that. I think that's what's currently being used, but that's just a guess. – linux_confusion Mar 29 '18 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.