2017-03-13 10 views
5

Ich habe Python3.6 auf ubuntu16.04 installiert und sqlite3 installiert. Wenn ich in Python2 bin, kann ich sqlite erfolgreich importieren, aber in Python3 habe ich einen Importfehler bekommen. Ich habe viele Methoden von Google ausprobiert, aber es funktioniert immer noch nicht. Ich möchte wissen, wie ich es lösen kann.python3.6 import sqlite3 error

Python 3.6.0 (default, Mar 13 2017, 06:38:19) 
[GCC 5.4.0 20160609] on linux 
Type "help", "copyright", "credits" or "license" for more information. 

> import sqlite3 

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

ModuleNotFoundError: No module named '_sqlite3' 
+3

Wie genau haben Sie installieren Python 3? Wie genau haben Sie das SQLite-Modul installiert? –

+0

Ich kompilierte den Quellcode zu installiertem Python 3. und installierte sqlite mit "sudo apt-get install sqlite3" – dragon

+0

Ich empfehle, dass anstatt die Quelle selbst zu kompilieren, Sie es von einem vorgefertigten Paket installieren. Anleitung hier: http://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get –

Antwort

2

Sie können python3 und sqlite selbst installieren. try this.

Oder Sie können es versuchen, wie folgt,

 
1. install sqlite3 
$ wget https://www.sqlite.org/2017/sqlite-autoconf-3170000.tar.gz --no-check-certificate 
$ tar zxvf sqlite-autoconf-3170000.tar.gz 
$ cd sqlite-autoconf-3170000 
$ ./configure --prefix=/usr/local/sqlite3 --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1" 

2. install python3.6 
$ cd Python-3.6.0 
$ LD_RUN_PATH=/usr/local/sqlite3/lib ./configure --prefix=/usr/local/python3.6 LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include" 
$ LD_RUN_PATH=/usr/local/sqlite3/lib make 
$ LD_RUN_PATH=/usr/local/sqlite3/lib make install 

+0

danke, ich installiert python3.6 und sqlite als unten, aber es funktioniert immer noch nicht.und dann fand ich python3.5 auf ubuntu16.04, die sqlite3 erfolgreich importieren kann – dragon

+0

Wenn python3.5 gut funktioniert, denke ich, dass Sie die * .so-Datei direkt an den Speicherort kopieren können python3.6. – ismtlee