如何打开 Python 3 安装的 sqlite3?

Sni*_*_3B 1 python sqlite python-3.x

Ubuntu python2 和 python3 都可以导入 sqlite3,但是我无法输入sqlite3命令提示符来打开它,它说没有安装 sqlite3,如果我想从 python 中使用它,我应该单独使用 apt-get 安装 sqlite3 还是我可以找到它在python的某个目录中,将其添加到路径并直接在命令行中使用。

我在mac上也安装了python3.5,mac自带python2,可以在命令行中type使用sqlite3,sqlite3版本是3.8.10.2,貌似是python2安装的,但是python3.5安装了不同版本的sqlite3 ,我在哪里可以找到它?

Rob*_*oon 5

在 python 上使用 sqlite3 不需要安装任何东西。

关于 sqlite:https : //www.sqlite.org/about.html

如果你有使用数据库的经验,你可以认为 sqlite3 是一个类似数据库包含表的文件。

因为python支持sqlite3,所以可以新建一个sqlite3文件。

此示例仅使用 python 创建一个新的 example.db 文件(如果不存在)。

import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()

# Create table
c.execute('''CREATE TABLE stocks
             (date text, trans text, symbol text, qty real, price real)''')

# Insert a row of data
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")

# Save (commit) the changes
conn.commit()

# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
Run Code Online (Sandbox Code Playgroud)

阅读此文档:https : //docs.python.org/2/library/sqlite3.html

但我建议您安装 sqlite 以使用命令行 Shell For SQLite。

$ sqlite3 ex1
SQLite version 3.8.5 2014-05-29 12:36:14
Enter ".help" for usage hints.
sqlite> create table tbl1(one varchar(10), two smallint);
sqlite> insert into tbl1 values('hello!',10);
sqlite> insert into tbl1 values('goodbye', 20);
sqlite> select * from tbl1;
hello!|10
goodbye|20
sqlite>
Run Code Online (Sandbox Code Playgroud)