2015-11-13 28 views
0

Ubuntu的python2和python3都可以導入sqlite3的,但我不能在命令提示符下鍵入sqlite3打開它,它說的sqlite3沒有安裝,如果我想使用它的蟒蛇,我應該安裝sqlite3的單獨使用apt-get或者我能找到它在Python的一些目錄,將它添加到路徑,並直接在命令行中使用。如何打開被Python 3安裝sqlite3的?

我還在mac上安裝了python3.5,mac上裝有python2,並且我可以在命令行中使用sqlite3,類型爲sqlite3,它的版本是3.8.10.2,似乎是由python2安裝的,但安裝了python3.5不同版本的sqlite3的,我在哪裏可以找到它?

回答

3

你不需要安裝任何東西對蟒蛇使用sqlite3的。

關於sqlite的:https://www.sqlite.org/about.html

如果您在使用數據庫, 你能想到的sqlite3就像一個數據庫中的文件包括表的一個體驗。

因爲Python支持sqlite3的,你可以做一個新的sqlite3的文件。

本例創建一個新的example.db文件,如果不存在只能使用python。

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() 

閱讀本文檔:https://docs.python.org/2/library/sqlite3.html

但我建議你安裝sqlite的使用命令行Shell 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> 
0

正如Robert Moon所說,sqlite3自2.5版以來包含在Python中,您可以直接使用它。看他的帖子來舉個例子。

Sqlite是大多數管理存儲在文件中的SQL數據庫的庫。所以很容易在軟件或網站中使用它,並使用一種可用於向數據庫發送請求(存儲在文件中)的語言。

如果你想使用sqlite3的一個python腳本之外,在Ubuntu,你要安裝的軟件包

sudo apt-get install sqlite3 

然後你可以運行SQLite的終端

sqlite3 

發出請求,創建新的數據庫等。

0

任何發現自己在這裏的Cygwin用戶:運行Cygwin安裝.exe ...

選擇「類別」,「數據庫」,然後有一個項目顯示「sqlite3客戶端訪問sqlite3數據庫」或單詞。