11

I installed Python3.6 on ubuntu16.04 and installed sqlite3. When in python2, I can import sqlite successfully, but in python3 I got an import error. I tried many methods from Google, but it still doesn't work. I want to know how to solve it.

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'
gen_Eric
228k42 gold badges304 silver badges343 bronze badges
asked Mar 13, 2017 at 14:26
4
  • 4
    How exactly did you install Python 3? How exactly did you install the SQLite module? Commented Mar 13, 2017 at 14:31
  • I compiled the source code to installed Pythhon 3。and installed sqlite with "sudo apt-get install sqlite3" Commented Mar 14, 2017 at 0:05
  • I recommend that instead of compiling the source yourself, you install it from a pre-built package. Instructions here: askubuntu.com/questions/865554/… Commented Mar 15, 2017 at 4:46
  • thanks, it's helpful Commented Mar 15, 2017 at 12:51

2 Answers 2

4

sqlite3 will comes with python itself. I also get the same problem i just uninstalled the python3.6 and installed again.

uninstall existing python:

sudo apt-get remove --purge python3.6

Install python3.6:

sudo apt install -y \
 build-essential \
 checkinstall
sudo apt install -y \
 libreadline-gplv2-dev \
 libncursesw5-dev \
 libssl-dev \
 libsqlite3-dev \
 tk-dev \
 libgdbm-dev \
 libc6-dev \
 libbz2-dev
PYTHON_VERSION=3.6.0
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
tar xvf Python-${PYTHON_VERSION}.tar.xz
cd Python-${PYTHON_VERSION}/
./configure
sudo make altinstall

It works!

GabLeRoux
18.2k17 gold badges68 silver badges83 bronze badges
answered Jul 18, 2018 at 13:50
Sign up to request clarification or add additional context in comments.

Comments

3

You can install python3 and sqlite by yourself. try this.

Or you can try it as follows,

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 
answered Mar 14, 2017 at 6:30

3 Comments

thanks, I installed python3.6 and sqlite as below, but it still dosen't work。and then i found python3.5 on ubuntu16.04,which can import sqlite3 successful
If python3.5 works well, I think you can copy the *.so file directly to the location of python3.6.
you can try python3.5 for sqlite . The only ption i found.

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.