How to update the version of SQLite used by the Python SQLite3 module on Mac?

I would like to use SQLite version 3.8 with Python, but the SQLite3 module uses an older version. I installed SQLite version 3.8.4.3 on my Mac, but sqlite3.sqlite_version still returns 3.7.13.

I have searched quite a lot in SO and elsewhere, but cannot find a definitive answer.

Thanks!

+5
source share
3 answers

From your comments, your problem is that your pre-installed sqlite 3.7 is higher in your path than your third-party 3.8. This means that when you create pysqlite2 , by default it will find and use this 3.7, so it won’t do you any good. And you probably don't want to change all the way to handle this.

But it’s fine if at the start of the build phase 3.8 is found, it doesn’t matter what comes first at runtime; the path to 3.8 will be baked into the module. There are several ways to do this, but the simplest:

 $ brew install sqlite3 $ sudo -s # LDFLAGS=-L/usr/local/opt/sqlite/lib CPPFLAGS=-I/usr/local/opt/sqlite/include pip2.7 install pysqlite # ^D $ python >>> import sqlite3 >>> sqlite3.sqlite_version '3.7.13' >>> import pysqlite2.dbapi2 >>> pysqlite2.dbapi2.sqlite_version '3.8.6' 

The LDFLAGS and CPPFLAGS came from the output of the brew install sqlite3 . If you installed sqlite3 any other way, you need to get the appropriate values ​​- perhaps /usr/local/lib and /usr/local/include , but if not, search for libsqlite3.dylib and sqlite3.h .

Please note that if you follow these steps, you will get a low-fat version of libsqlite3 , which means that pysqlite2 will not work in 32-bit mode. I doubt the problem is for you, but if so, you can simply install it --universal or use a different installer instead of Homebrew.

+1
source

If you are using Anaconda as a package manager, run conda install -c anaconda sqlite .

Run python -c "import sqlite3; print(sqlite3.sqlite_version)" to confirm that you have the latest version installed.

A source

+1
source

I think the easiest way is to upgrade your Python to the latest version, because sqlite3 comes with Python.

Otherwise, you will have to upgrade the pysqlite package. On Linux, there is a precompiled python-sqlite package.

You can do this using easy_install. To create this package you need packages. Sure, create pysqlite with the new installed version of sqlite3 in your case 3.8.4.3.

 sudo easy_install pysqlite 

or

 sudo pip install --upgrade pysqlite 
0
source

Source: https://habr.com/ru/post/1204587/


All Articles