How do I upgrade the SQLite version used by Python's SQLite3 module on Mac?
From your comments, your problem is that your pre-installed sqlite 3.7 comes higher on your path than your third-party 3.8. This means that when you build pysqlite2
, by default, it will find and use that 3.7, so it's not doing you any good. And you probably don't want to change around your whole path just to deal with this.
But that's fine, as long as the 3.8 is found first at build time, it doesn't matter what comes first at runtime; the path to 3.8 will be baked into the module. There are a number of ways to do this, but the simplest is something like this:
$ 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
variables came from the output of the brew install sqlite3
step. If you've installed sqlite3
in some other way, you'll need to get the appropriate values—possibly /usr/local/lib
and /usr/local/include
, but if not, search for libsqlite3.dylib
and sqlite3.h
.
Note that if you follow exactly these steps, you'll get a non-fat version of libsqlite3
, meaning that pysqlite2
won't work in 32-bit mode. I doubt that's an issue for you, but if it is, you can just install it --universal
, or use a different installer instead of Homebrew.
Configure python sqlite3 module to use different (newer version) sqlite system lib (Upgrade sqlite)
Use binary package of pysqlite3:
https://github.com/coleifer/pysqlite3
in your requirements, add
pip install pysqlite3-binary
in python code, use pysqlite3:
import pysqlite3
(...) conn = pysqlite3.connect(r"filename") (...)
instead of sqlite3.
Alternative, as Anthony suggested: swapping the system binary
You can swap the binary of the system:
import sys
sys.modules['sqlite3'] = __import__('pysqlite3')
And the you don't have to use pysqlite3
in your code.
How to update python-sqlite on mac osx
You'll first need to install SQLite, then build and install pysqlite
, making sure that it's building against your newly installed version of sqlite and not the system's version of sqlite. Alternately, if pysqlite is dynamically linked, you might be able to fiddle with LD_LIBRARY_PATH
to make your existing pysqlite load the newer version of the library.
For more, see: https://groups.google.com/group/python-sqlite/browse_thread/thread/9fb6694c803431eb
How can I add the sqlite3 module to Python?
You don't need to install sqlite3
module. It is included in the standard library (since Python 2.5).
django can't find new sqlite version? (SQLite 3.8.3 or later is required (found 3.7.17))
To check which version of SQLite Python is using:
$ python
Python 3.7.3 (default, Apr 12 2019, 16:23:13)
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.27.2'
For me the new version of sqlite3 is in /usr/local/bin so I had to recompile Python, telling it to look there:
sudo LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations
sudo LD_RUN_PATH=/usr/local/lib make altinstall
Related Topics
I Am Trying to Split a Full Name to First Middle and Last Name in Pandas But I Am Stuck At Replace
Find First Non-Zero Value in Each Column of Pandas Dataframe
How to Make My Discord.Py Bot Play Mp3 in Voice Channel
How to Set the Precision on Str(Numpy.Float64)
Applying a Function Along a Numpy Array
Count Unique Words in a Text File (Python)
How to Find Factors of a Number Using the Simplest Python Method
Populating Pandas Columns Based on Values in Other Columns
Cursor.Fetchone() Returns None But Row in the Database Exists
Convert CSV File to Pipe Delimited File in Python
Recursive Function to Go Inside Dictionary of Dictionary
Navigating Through Pagination With Selenium in Python
Get Absolute Paths of All Files in a Directory
Pandas: How to Return Rows Where a Column Has a Line Breaks/New Line ( \N ) in Its Cell
How to Obtain Second and Fourth Word from Each Line in a File