在网址 https://www.sqlite.org/download.html 下载

解压到windows下某个目录,如D:\数据\sqlite-tools-win32-x86-3280000
在path环境变量中加入此目录,可以在【系统属性】-【环境变量】中添加。也可以临时如下命令行cmd添加
set path=%path%;D:\数据\sqlite-tools-win32-x86-3280000
安装sqlite3的python库, 如"C:\Program Files\Python37\python.exe" -m pip install pysqlite3
之后就可以编写sqlite3的python代码,调用它了,如
from faker import Faker
import sqlite3
fake= Faker("zh_cn")
conn= sqlite3.connect("test.db");
c=conn.cursor()
c.execute("create table user( id varchar(20) \
primary key, name varchar(20))")
for i in range(10):
c.execute("insert into user(id, name) \
values ('{}', '{}')".format(i,fake.name()))
c.execute("select * from user")
result=c.fetchall()
print(result)
运行结果如下
![]()
博客介绍了在Windows系统下使用Python调用SQLite3的方法。先从指定网址下载SQLite3并解压到指定目录,接着在path环境变量中添加该目录,也可通过命令行临时添加。然后安装SQLite3的Python库,最后即可编写代码调用。
1203





