如何在我的python3.4中成功导入sqlite3?

时间:2014-12-14 14:56:57

标签: sqlite python-3.4

我的debian7中有两个python版本,一个是python2.7系统默认版本,另一个是python3.4编译安装这种方式。

 apt-get update
 apt-get upgrade
 apt-get install build-essential
 wget http://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz
 tar -zxvf Python-3.4.0.tgz
 cd Python-3.4.0
 mkdir /usr/local/python3.4
 ./configure --prefix=/usr/local/python3.4
 make
 make install
 ln -s /usr/local/python3.4/bin/python3.4   /usr/bin/python3.4
 ln -s /usr/local/python3.4/bin/pip3.4   /usr/bin/pip3.4

我已经在我的debian上安装了sqlite。

sudo apt-get install sqlite3 libsqlite3-dev 

在python2.7中

root@rebuild:~# python
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3

在python3.4中

root@rebuild:~# python3.4
Python 3.4.0 (default, Nov 27 2014, 13:54:17)
[GCC 4.7.2] 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/python3.4/lib/python3.4/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/python3.4/lib/python3.4/sqlite3/dbapi2.py", line 26, in <module>
    from _sqlite3 import *
ImportError: No module named '_sqlite3'

如何在python3.4中成功导入sqlite3?

2 个答案:

答案 0 :(得分:2)

从提供的信息和提供的订单中,看起来您在安装sqlite-dev软件包之前从源代码安装了python 3.4。如果你仔细观察python 3.4安装,你会发现它没有构建任何数量的模块(其中一个是_sqlite3)。

解决方案:现在重新安装3.4 sqlite3 dev可用。

答案 1 :(得分:1)

我同样淹没了这个问题,这个流程在oracel-linux / python3中成功

1.下载并安装sqlite3

$ tar sqlite-autoconf-3180000.tar.gz  
$ cd sqlite-autoconf-3180000  
$./configure --prefix=/usr/local/sqlite3 && make && make install

2.Export LD_LIBRARY_PATH

$ export LD_LIBRARY_PATH=/usr/local/lib

3.下载并安装python3.6

$ tar Python-3.6.0.tar.xz  
$ cd Python-3.6.0  
$ ./configure && make && make install