如何指示Python使用我自己编译的SQLite3?

问题描述 投票:0回答:1

我已经从下载页面编译了我自己版本的 SQLite3 合并 tarball,并希望将其包含到我在 MacO 上的 Python3 脚本中。有没有办法通过

import sqlite3
做到这一点?例如,是否可以指示 Python 使用我自己的版本?

python macos sqlite
1个回答
0
投票

pysqlite3
有构建静态链接库选项

针对特定版本构建

pysqlite3
静态链接 SQLite,需要获取SQLite3源代码并复制
sqlite3.c
sqlite3.h
进入源代码树。

# Download the latest release of SQLite source code and build the source
# amalgamation files (sqlite3.c and sqlite3.h).
$ wget https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release \
    -O sqlite.tar.gz
$ tar xzf sqlite.tar.gz
$ cd sqlite/
$ ./configure
$ make sqlite3.c

# Copy the sqlite3 amalgamation files into the root of the pysqlite3 checkout
# and run build_static + build:
$ cp sqlite/sqlite3.[ch] pysqlite3/
$ cd pysqlite3
$ python setup.py build_static build

您现在拥有一个静态链接的、完全独立的

pysqlite3

按照上述说明您应该能够做到

from pysqlite3 import dbapi2 as sqlite3
print(sqlite3.sqlite_version)

这将显示所使用的 SQLite 版本,因为我无权访问

MacOS

我无法测试上述方法,请自己尝试一下并写下它是否有效。

© www.soinside.com 2019 - 2024. All rights reserved.