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

时间:2021-09-23 17:16:54

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.

我希望在Python中使用SQLite版本3.8,但是SQLite3模块使用的是过期版本。我在Mac上安装了SQLite 3.8.4.3版本,但是sqlite3。sqlite_version仍然返回3.7.13。

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

我在SO和其他地方做了很多搜索,但似乎找不到一个明确的答案。

Thanks!

谢谢!

2 个解决方案

#1


1  

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.

从您的评论中,您的问题是,您预先安装的sqlite 3.7在您的路径上比您的第三方3.8更高。这意味着在默认情况下构建pysqlite2时,它会发现并使用这个3.7,所以它对您没有任何好处。你可能不想为了解决这个问题而改变整个道路。

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:

但这很好,只要3.8在构建时被发现,在运行时首先发生什么并不重要;到3.8的路径将被放入模块中。有很多方法可以做到这一点,但最简单的方法是这样的:

$ 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.

LDFLAGS和CPPFLAGS变量来自brew install sqlite3步骤的输出。如果您以其他方式安装了sqlite3,那么您将需要获得适当的值——可能是/usr/local/lib和/usr/local/include,但如果不是,则搜索libsqlite3。dylib 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.

注意,如果您遵循这些步骤,您将得到libsqlite3的非胖版本,这意味着pysqlite2不能在32位模式下工作。我怀疑这对你来说是个问题,但如果是的话,你可以安装它——通用的,或者使用不同的安装程序而不是自制的。

#2


0  

I think the easiest way is to update your Python to the latest version because sqlite3 is shipped with Python.

我认为最简单的方法是将Python更新到最新的版本,因为sqlite3附带了Python。

Otherwise have to update the pysqlite package as well. Under Linux there is a precompiled package python-sqlite.

否则也必须更新pysqlite包。在Linux下有一个预先编译的包python-sqlite。

You can do that by using easy_install. For building this package you need some packages. Nessecerily build pysqlite with the new installed version of sqlite3, in your case 3.8.4.3.

您可以使用easy_install来实现这一点。要构建这个包,需要一些包。Nessecerily用sqlite3的新安装版本构建了pysqlite,在你的例子中是3.8.4.3。

sudo easy_install pysqlite

or

sudo pip install --upgrade pysqlite

#1


1  

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.

从您的评论中,您的问题是,您预先安装的sqlite 3.7在您的路径上比您的第三方3.8更高。这意味着在默认情况下构建pysqlite2时,它会发现并使用这个3.7,所以它对您没有任何好处。你可能不想为了解决这个问题而改变整个道路。

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:

但这很好,只要3.8在构建时被发现,在运行时首先发生什么并不重要;到3.8的路径将被放入模块中。有很多方法可以做到这一点,但最简单的方法是这样的:

$ 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.

LDFLAGS和CPPFLAGS变量来自brew install sqlite3步骤的输出。如果您以其他方式安装了sqlite3,那么您将需要获得适当的值——可能是/usr/local/lib和/usr/local/include,但如果不是,则搜索libsqlite3。dylib 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.

注意,如果您遵循这些步骤,您将得到libsqlite3的非胖版本,这意味着pysqlite2不能在32位模式下工作。我怀疑这对你来说是个问题,但如果是的话,你可以安装它——通用的,或者使用不同的安装程序而不是自制的。

#2


0  

I think the easiest way is to update your Python to the latest version because sqlite3 is shipped with Python.

我认为最简单的方法是将Python更新到最新的版本,因为sqlite3附带了Python。

Otherwise have to update the pysqlite package as well. Under Linux there is a precompiled package python-sqlite.

否则也必须更新pysqlite包。在Linux下有一个预先编译的包python-sqlite。

You can do that by using easy_install. For building this package you need some packages. Nessecerily build pysqlite with the new installed version of sqlite3, in your case 3.8.4.3.

您可以使用easy_install来实现这一点。要构建这个包,需要一些包。Nessecerily用sqlite3的新安装版本构建了pysqlite,在你的例子中是3.8.4.3。

sudo easy_install pysqlite

or

sudo pip install --upgrade pysqlite