Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named '_sqlite3'

On Redhat 4.4.7-18 I am trying to run python3 code using sqlite, but I get the following import error:

Traceback (most recent call last):
  File "database.py", line 7, in <module>
    import sqlite3
  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'

I tried to install it:

>sudo pip install sqlite3
Collecting sqlite3
  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/sqlite3/

(while the network is reachable...) and with the following command:

> sudo yum install sqlite-devel
Loaded plugins: post-transaction-actions, product-id, refresh-packagekit,
              : rhnplugin, search-disabled-repos, security, subscription-manager
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
Package sqlite-devel-3.6.20-1.el6_7.2.x86_64 already installed and latest version
Nothing to do

So it is installed and not installed? Any suggestion how I can solve the original problem?

like image 894
Alex Avatar asked May 16 '17 06:05

Alex


People also ask

What is the correct way to install sqlite3 in Python?

You don't need to install sqlite3 module. It is included in the standard library (since Python 2.5).


3 Answers

Not a direct answer but I ended up here with my search engine... So for my fellow web-surfers:

I had a similar issue, but on ubuntu 16.04 with a manually compile python3.6 version :

    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

I had to install libsqlite3-dev (sudo apt install libsqlite3-dev) and compile from the start python3.6 to make it work.

like image 138
deterralba Avatar answered Oct 22 '22 02:10

deterralba


Yep.

sudo yum install sqlite-devel

Followed by rebuild of Python 3.8.3 from source did the trick. Thx!

like image 7
user2133121 Avatar answered Oct 22 '22 03:10

user2133121


I had this issue on linux mint 20 after sqlite3 successfully installed

from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

also, could not import sqlite3 into python interpreter

Fix:

sudo apt install libsqlite3-dev

cd your python installer directory

./configure sudo make install

like image 3
Katja Avatar answered Oct 22 '22 02:10

Katja