如何在Mac上升级Python的SQLite3模块使用的SQLite版本?

如何在Mac上升级Python的SQLite3模块使用的SQLite版本?

问题描述:

我想将SQLite 3.8版与Python一起使用,但是SQLite3模块使用的是过时的版本.我已经在Mac上安装了SQLite版本3.8.4.3,但sqlite3.sqlite_version仍返回3.7.13.

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.

我已经在SO和其他地方进行了大量搜索,但似乎找不到明确的答案.

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

谢谢!

根据您的评论,您的问题是,预安装的sqlite 3.7的运行路径比第三方3.8的路径高.这意味着在默认情况下构建pysqlite2时,它将找到并使用该3.7,因此对您没有任何好处.而且您可能不想为了解决这个问题而改变自己的整个路径.

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.

但是没关系,只要在构建时首先找到3.8,就在运行时先找到3.8是没有关系的. 3.8的路径将被烘焙到模块中.有很多方法可以做到这一点,但是最简单的方法是这样的:

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'

LDFLAGSCPPFLAGS变量来自brew install sqlite3步骤的输出.如果以其他方式安装了sqlite3,则需要获取适当的值-可能是/usr/local/lib/usr/local/include,但如果没有,请搜索libsqlite3.dylibsqlite3.h.

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.

请注意,如果完全按照 的步骤进行操作,则会得到libsqlite3的非胖版本,这意味着pysqlite2在32位模式下将不起作用.我怀疑这对您来说是个问题,但如果是这样,您可以直接安装--universal,或使用其他安装程序代替Homebrew.

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.