更新python内置sqlite3_如何在Mac上升级Python的SQLite3模块使用的SQLite版本?

I would like to use the SQLite version 3.8 with Python, but the SQLite3 module is using an out of date version. I've installed SQLite version 3.8.4.3 on my Mac, but sqlite3.sqlite_version still returns 3.7.13.

I've done quite a bit of searching on SO and elsewhere, but can't seem to find a definitive answer.

Thanks!

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值