2017-01-03 44 views
3

SQLite是工作正常使用Python 2.7,但是當我試圖在Python導入此3提示錯誤sqlite3的是不是能夠在Python導入3

> Traceback (most recent call last): File "dbConnection.py", line 1, 
> in <module> 
>  import sqlite3 File "/usr/local/lib/python3.4/sqlite3/__init__.py", line 23, in <module> 
>  from sqlite3.dbapi2 import * File "/usr/local/lib/python3.4/sqlite3/dbapi2.py", line 27, in <module> 
>  from _sqlite3 import * ImportError: No module named '_sqlite3' 

刪除這個錯誤我試圖重新安裝sqlite3通過

sudo apt-get install sqlite3 

但它說包已經存在。在那之後我將嘗試

pip3 install sqlite3 

安裝它,但同時再次安裝提示錯誤

Collecting sqlite3 
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/ 
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/ 
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb5ff3bc550>, 'Connection to 196.1.114.80 timed out. (connect timeout=15)')': /simple/sqlite3/ 
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/ 
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/ 
Could not find a version that satisfies the requirement sqlite3 (from versions:) 
No matching distribution found for sqlite3 

,但我的連接工作正常... 現在我應該怎麼做,我能在python 3中導入sqlite3?

回答

1

sqlite3可選標準庫的一部分。它是在編譯和安裝Python 3時編譯的,但只有在正確的sqlite3包含文件(開發標頭)可用時纔會編譯。

如果你自己編譯並安裝了Python 3,安裝依賴(libsqlite3-devsqlite-devel或相似的,這取決於你的Linux發行版,例如),然後重新編譯和重新安裝Python 3

外部,圖書館保持爲pysqlite;但是that release doesn't support Python 3。即使那樣,要安裝它,你仍然需要那些sqlite開發文件,並且你需要將它移植到Python 3.你可能只需重新編譯Python 3.

+0

我使用的是Ubuntu 16.04,而且我已經安裝libsqlite3-dev的一些網站建議,但沒有工作... :( –

+0

編譯時得到一個錯誤: ***警告:重命名「_sqlite3」自導入失敗:build/lib.linux-x86_64-3.6/_sqlite3.cpython-36m-x86_64-linux-gnu.so:undefined symbol:sqlite3_stmt_readonly 從https://github.com/ghaering/pysqlite/issues/85,它可能是由舊的sqlite版本引起的。 –