2

I'm using Ubuntu 16.04 and I'm trying to learn Django and I installed it in my virtual environment and named it myenv, and I started a project named mysite. When I tried to run the manage.py file, it kept saying sqlite3 is not installed. I did install it, but it is saying the same error. When I run python3 manage.py migrate, it says:

"ModuleNotFoundError: No module named '_sqlite3'"

I installed sqlite using the commands below:

sudo add-apt-repository ppa:jonathonf/backports
sudo apt-get upgrade
sudo apt-get install sqlite3
8
  • 1
    When you run command sqlite3 in terminal, do you get the sqlite> prompt Commented Jun 24, 2018 at 17:00
  • yeah, i get that Commented Jun 24, 2018 at 17:58
  • but doesnot work Commented Jun 24, 2018 at 17:58
  • install sqlite3 using sudo add-apt-repository ppa:jonathonf/backports and sudo apt-get update && sudo apt-get install sqlite3 Commented Jun 24, 2018 at 18:23
  • Which Django version are you using? I had the same problem. Then I downgraded Django and things worked again. Commented Jun 25, 2018 at 15:40

3 Answers 3

3

I saw the same error too with Python 3.7 in Ubuntu Xenial 16.04 and the following fixed it for me:

Install libsqlite3:

sudo apt install libsqlite3-dev

Reinstall Python 3.7:

wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar -xvf Python-3.7.3.tgz 
cd Python-3.7.3/
./configure
make
sudo make install
sudo ln -s /usr/local/bin/python3.7 /usr/bin/python3
Sign up to request clarification or add additional context in comments.

Comments

1

This relates to ModuleNotFoundError: No module named '_sqlite3'

The problem might be that your Python installation does not include sqlite3, which is usually in the standard lib.

You should try installing libsqlite3-dev (sudo apt install libsqlite3-dev), then reinstalling Python.

4 Comments

do i have to uninstall the python to run that command or i can do with it
You can run the command without uninstalling Python, but it will not solve your issue.
@NikeshThapa What version of Python are you using? And how did you install it? (Some repo? Compiled it?)
sudo apt install python3
0

I'm using python 3.6 and django version 1.11.3 I got the same error it was fixed doing these steps:

  1. Install pysqlite3: pip install pysqlite3

  2. change base.py line 33 to:

from pysqlite3 import dbapi2 as Database

The base.py file is located under "lib" directory of your virtualenv: path_to_virtualenv/lib/python_interpreter_name/site-packages/django/db/backends/sqlite3/base.py

In my case: path_to_my_venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py

Update: If you encountered the same problem in newer django versions (such as "2.0.7") you should change line 8 of base.py.(tested with django version "2.0.7")

Comments

Your Answer

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.