Let's use different versions of SQLite3 from Python3!

Introduction

In Python3, I had to use various versions of SQLite3 and SQLite3 that I improved by myself, so I summarized it as a memorandum.

environment

The OS is CentOS 7.7. You can access the outside by setting Proxy etc.

$ cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

First, install Python3. The version of Python3 is 3.6.8.

$ sudo yum install python3
$ python3 --version
Python 3.6.8

Check the version of SQLite3 with the SQLite3 command and Python3.

$ sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
$ python3
Python 3.6.8 (default, Aug  7 2019, 17:28:10) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'

I have SQLite 3.7.17 installed and Python3 is also using SQLite 3.7.17.

Using SQLite 3.31.1 with Python3

Get the latest version of SQLite3 (3.31.1). After getting it with wget and extracting it, change the directory name to sqlite-3.31.01.

$ wget https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz
$ tar zxvf sqlite-autoconf-3310100.tar.gz
$ mv sqlite-autoconf-3310100 sqlite-3.31.01

Build SQLite3.

$ cd sqlite-3.31.01
$ ./configure
$ make
$ ./sqlite3 --version
3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837bb4d6

Check the file. The SQLite3 library is located in the directory .libs.

$ ls -a
.            Makefile.fallback  config.guess   install-sh     sqlite3-shell.o    sqlite3.pc
..           Makefile.in        config.log     libsqlite3.la  sqlite3-sqlite3.o  sqlite3.pc.in
.deps        Makefile.msc       config.status  libtool        sqlite3.1          sqlite3.rc
.libs        README.txt         config.sub     ltmain.sh      sqlite3.c          sqlite3ext.h
INSTALL      Replace.cs         configure      missing        sqlite3.h          tea
Makefile     aclocal.m4         configure.ac   shell.c        sqlite3.lo
Makefile.am  compile            depcomp        sqlite3        sqlite3.o
$ ls -a .libs
.   libsqlite3.a   libsqlite3.lai  libsqlite3.so.0      sqlite3.o
..  libsqlite3.la  libsqlite3.so   libsqlite3.so.0.8.6

In the LD_LIBRARY_PATH environment variable, specify the absolute path of .libs.

$ export LD_LIBRARY_PATH=$HOME/sqlite-3.31.01/.libs
$ echo $LD_LIBRARY_PATH
/home/mototaka/sqlite-3.31.01/.libs

Let's check the version of SQLite3 with Python3.

$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.31.1'

From Python3, we have confirmed that the latest version of SQLite, 3.31.1, is available. Let's also check with the SQLite native sqlite_version () function.

$ python3
>>> import sqlite3
>>> con = sqlite3.connect(":memory:")
>>> cur = con.cursor()
>>> cur.execute("SELECT sqlite_version()")
>>> cur.fetchone()
('3.31.1',)

Similarly, from Python3, we have confirmed that the latest version of SQLite, 3.31.1, is available.

Using SQLite 3.20.1 with Python3

Get SQLite3 3.20.1 and build it.

$ wget https://www.sqlite.org/2017/sqlite-autoconf-3200100.tar.gz 
$ tar zxvf sqlite-autoconf-3200100.tar.gz
$ mv sqlite-autoconf-3200100 sqlite-3.20.01
$ cd sqlite-3.20.01/
$ ./configure
$ make
$ ./sqlite3 --version
3.20.1 2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34

Now specify the relative path of .libs in the environment variable LD_LIBRARY_PATH.

$ export LD_LIBRARY_PATH=./libs

Let's check the version of SQLite3 with Python3.

$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.20.1'

From Python3, I was able to confirm that the built SQLite 3.20.1 can be used. By specifying the relative path of .libs in LD_LIBRARY_PATH, it is possible to use various SQLite from Python3 by changing the directory in the following environment.

$ ls
sqlite3.00.08  sqlite3.06.23.1  sqlite3.12.02  sqlite3.18.02  sqlite3.23.00  sqlite3.29.00
sqlite3.01.06  sqlite3.07.17    sqlite3.13.00  sqlite3.19.03  sqlite3.24.00  sqlite3.30.01
sqlite3.02.07  sqlite3.08.11.1  sqlite3.14.02  sqlite3.2.8    sqlite3.25.03  sqlite3.31.01
sqlite3.03.17  sqlite3.09.03    sqlite3.15.02  sqlite3.20.01  sqlite3.26.00
sqlite3.04.02  sqlite3.10.02    sqlite3.16.02  sqlite3.21.00  sqlite3.27.02
sqlite3.05.09  sqlite3.11.01    sqlite3.17.02  sqlite3.22.00  sqlite3.28.00

Summary

In the case of SQLite, unlike other databases, it is difficult to change the database to connect with driver and connection information, and I thought that I had to improve the source code of Python3 at worst, but I use the environment variable LD_LIBRARY_PATH. This made it surprisingly easy to use different versions of SQLite3. Also, since I haven't used root privileges other than installing Pyhton3 this time, I think it's a good idea to easily try out the operation check with various versions.

If you find any mistakes or concerns about the description, we would appreciate it if you could give us feedback in the edit request or comment.

Recommended Posts

Let's use different versions of SQLite3 from Python3!
Use thingsspeak from python
Use fluentd from python
Use MySQL from Python
Use multiple versions of python environment with pyenv
Graduate from Python (x, y) and try mixing different versions of Python @Windows
Use MySQL from Python
Use mecab-ipadic-neologd from python
Let's use the Python version of the Confluence API module.
Let's use the open data of "Mamebus" in Python
Let's use def in python
Let's use python janome easily
Install multiple versions of Python
Connect to sqlite from python
Use e-Stat API from Python
Different from the import type of python. from A import B meaning
Let's use Watson from Python! --How to use Developer Cloud Python SDK
Let's use usercustomize.py instead of sitecustomize.py
Use Stanford Core NLP from Python
Let's use tomotopy instead of gensim
How to use SQLite in Python
Existence from the viewpoint of Python
Read and use Python files from Python
Forcibly use Google Translate from python
[Python Queue] Convenient use of Deque
[Introduction to Python] Let's use pandas
Use kabu StationĀ® API from Python
Use the Flickr API from Python
[Introduction to Python] Let's use pandas
Use fastText trained model from Python
[Introduction to Python] Let's use pandas
Use Google Analytics API from Python
How to avoid duplication of data when inputting from Python to SQLite.
Run different versions of Python (wsgi) apps on one development environment
[Python] Summary of how to use pandas
Use PostgreSQL data type (jsonb) from Python
Use machine learning APIs A3RT from Python
Learning notes from the beginning of Python 1
I'm stunned by the behavior of filter () due to different versions of Python
I want to use jar from python
[Introduction to Python] Let's use foreach with Python
Use Google Cloud Vision API from Python
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
Learning notes from the beginning of Python 2
[Question] How to use plot_surface of python
Get the contents of git diff from python
[Python] How to use two types of type ()
Firebase: Use Cloud Firestore and Cloud Storage from Python
Study from Python Hour7: How to use classes
The answer of "1/2" is different between python2 and 3
A memorandum of calling Python from Common Lisp
[Bash] Use here-documents to get python power from bash
Use OpenSeesPy regardless of OS or Python version
Summary of how to use MNIST in Python
python development environment -use of pyenv and virtualenv-
I want to use ceres solver from python
Summary of studying Python to use AWS Lambda
Wrap C ++ with Cython for use from Python
Use the nghttp2 Python module from Homebrew from pyenv's Python
Use Tor to connect from urllib2 [Python] [Mac]