How can I import sqlite3 successfully in my python3.4?

There are two versions of python in my debian7, one is the system default version of python2.7, the other is python3.4 which is compiled to install this way.

 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

      

I have installed sqlite this way on my debian.

sudo apt-get install sqlite3 libsqlite3-dev 

      

In 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

      

In 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'

      

How can I successfully import sqlite3 in my python3.4?

+3


source to share


2 answers


I have the same issue with this issue, this thread success in oracel-linux / python3

1.Download and install 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.Download and install python3.6

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

      

+1


source


From the information provided and the order presented, it looks like you installed python 3.4 from source before installing the sqlite-dev package. If you take a close look at how to install python 3.4, you would notice any number of modules it did not build (one of which would be _sqlite3).



Decision. Reinstall 3.4 now that sqlite3 is available.

+2


source







All Articles