4

There are two python version in my debian7, one is python2.7 the system default version, the other is python3.4 which 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 import sqlite3 in my python3.4 successfully?

asked Dec 14, 2014 at 14:56
3
  • 1
    What did you expect? If you install sqlite3 via your package manager it will only be compiled for your Python installations installed in the same way. Have you tried something like ./configure --with-sqlite? Commented Dec 14, 2014 at 15:10
  • i can import sqlite3 in python2.7, how can i import it in my python3.4? Commented Dec 14, 2014 at 16:10
  • think for filmor . apt-get install sqlite3 libsqlite3-dev and recompile to install python with ./configure --prefix=/usr/local/python3.4 --with-sqlite Commented Dec 15, 2014 at 1:09

2 Answers 2

2

From the information provided and order presented, it looks like you installed python 3.4 from source BEFORE making installing the sqlite-dev package available. If you watch the python 3.4 install closely you would have noticed any number of modules it did not build out (one of which would be _sqlite3).

Solution: Reinstall 3.4 now that sqlite3 dev is available.

answered Feb 7, 2015 at 7:18
Sign up to request clarification or add additional context in comments.

Comments

1

I have same swamped to this problem, this flow 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 
answered May 4, 2017 at 8:09

1 Comment

This solution worked for me as well. I already had python installed before the trying to update to the newest version of sqlite3. So I compiled it and then made sure to run the export in my virtualenv active file.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.