No module named _sqlite3
Asked Answered
L

29

241

I am trying to run a Django app on my VPS running Debian 5. When I run a demo app, it comes back with this error:

  File "/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in     import_module
    __import__(name)

  File "/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
    raise ImproperlyConfigured, "Error loading %s: %s" % (module, exc)

ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that     order): No module named _sqlite3

Looking at the Python install, it gives the same error:

Python 2.5.2 (r252:60911, May 12 2009, 07:46:31) 
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
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/python2.5/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3
>>>

Reading on the web, I learn that Python 2.5 should come with all the necessary SQLite wrappers included. Do I need to reinstall Python, or is there another way to get this module up and running?

Lenticular answered 31/7, 2009 at 4:21 Comment(1)
Same problem is for compiled python 3.5.5 from sourceVersed
I
283

It seems your makefile didn't include the appropriate .so file. You can correct this problem with the steps below:

  1. Install sqlite-devel (or libsqlite3-dev on some Debian-based systems)
  2. Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make install

Note

The sudo make install part will set that python version to be the system-wide standard, which can have unforseen consequences. If you run this command on your workstation, you'll probably want to have it installed alongside the existing python, which can be done with sudo make altinstall.

Interplead answered 27/6, 2014 at 10:28 Comment(19)
Thanks jammyWolf. I don't think that I "lost" the file after the first time that I ran configure, rather, that running configure with sqlite-devel already installed made all of this difference.Arable
The configuration saved me "./configure --enable-loadable-sqlite-extensions"Flirtatious
How can I install sqlite-devel ? I'm on a customized linux system.I just downloaded sqlite-autoconf-3100200.tar.gz and run ./configure,make && make install. After I recompile python3 it's still not working.Grotesque
For anyone reading this, make sure to add the configure option in the answer. That's what saved me too. Otherwise it won't matter that you've installed libsqlite3-dev.Waver
how do I check where the configure script is?Snide
Thanks for that. Also followed the following reddit post to compile Python: reddit.com/r/Python/comments/5unkb3/install_sqlite3_on_python_3/…Desma
Thanks a lot. I only had to re-download and execute ./configure --enable-loadable-sqlite-extensions && make && sudo make install Worked!Illstarred
I am using pyenv and after installing libsqlite3-dev I had to re-install your python version with pyenv install <python-version>.Mastiff
I had to install libsqlite3-dev on ubuntu 14.04, followed by step 2. Worked like a charm - thank you.Gritty
If I use python 3,6 mean to say pipenv --python 3.6 when creating the virtual environment then the problem gets solved.Cally
none of these solutions (ref: all on this page) work for amazon linux with python 3.8.0Effendi
Continued to fail for me because I had built sqlite3 in a custom dir. To fix I had to edit Python3's setup.py file. Look for sqlite_inc_paths assignment. Add your sqlite3 include dir to the list. That's was my last stumbling block.Keniakenilworth
For the actual working name (Debian-based distros), search for sqlite3 and dev packages like: sudo apt-cache search sqlite3 | grep dev, then you will find the "correct" name. For me it was libsqlite3-dev thus I did sudo apt install libsqlite3-devExtravehicular
This works for me. Centos 8, python 3.8.8 follow this one to install python3.8 computingforgeeks.com/how-to-install-python-3-on-centos 1. execute yum install sqlite-devel 2. go to the python source code(where you download) Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make installEvered
Works with pytho3.10 & RedHat 8.5.Prescript
I had install python3.8, and beause this problem I reinstall python3.8 as above, and then my system have two python3.8, one of that contain sqlite3 and another not contain sqlite3, @Grotesque ,"whereis python" can get python pathHairsplitting
Im using python3.7.13 on redhat linux distribution on Aws. Is there specific version of sqlite-devel that I need to install? I need to send info to another team so they can install for me.Amateurism
Worked for me to install Python 3.12.2 on Ubuntu 20.04. I have followed the tutorial howtogeek.com/install-latest-python-version-on-ubuntu and have adapted one line based on this answer: ./configure --enable-optimizations --enable-loadable-sqlite-extensionsRalston
On Amazon Linux 2023, I needed to install sudo yum install sqlite-devel.x86_64 first, then the sqlite options were available in the output of sudo ./configure --enable-optimizations --enable-loadable-sqlite-extensionsDisproof
W
103

I had the same problem with Python 3.5 on Ubuntu while using pyenv.

If you're installing the python using pyenv, it's listed as one of the common build problems. To solve it, remove the installed python version, install the requirements (for this particular case libsqlite3-dev), then reinstall the python version with

pyenv install <python-version> 

Then recreate virtualenv if needed.

Weinshienk answered 9/8, 2016 at 5:17 Comment(2)
It's not required to remove the installed version, pyenv install <python-version> will ask whether it should be overridden and re-compiles.Roomful
I used pyenv too and this works for me. Have to reinstall the whole environment so that the change will take effect. Remember to install libsqlite3-dev before that.Kilt
H
87

I had the same problem (building python2.5 from source on Ubuntu Lucid), and import sqlite3 threw this same exception. I've installed libsqlite3-dev from the package manager, recompiled python2.5, and then the import worked.

Hammel answered 30/4, 2010 at 19:46 Comment(1)
Exactly! You don't have to manually manipulate with binary files and environment. In my case I had already Python 2.7 built from source, so, to minify compilation I've executed apt-get install libsqlite3-dev; ./configure; make libinstall; make sharedinstall;Powerboat
P
41

my python is build from source, the cause is missing options when exec configure python version:3.7.4

./configure --enable-loadable-sqlite-extensions --enable-optimizations
make
make install

fixed

Preussen answered 15/10, 2019 at 9:9 Comment(3)
Didn't work. bash: ./configure: No such file or directoryKilt
i mean execute this command in the python source directory, like this:github.com/python/cpythonPreussen
You should cd to your python source directory and in the directory use the ./configure command @QuangHoàngMinhRocca
S
32
  1. Install the sqlite-devel package:

    yum install sqlite-devel -y

  2. Recompile python from the source:

    ./configure
    make
    make altinstall
    
Sterner answered 7/12, 2015 at 8:50 Comment(3)
I did 1(yum install sqlite-devl -y) this was okay. in #2, I got this err bash: ./configure: No such file or directory. How can I fix.Hotbed
Taking a lot of time on make command. What exactly this does? Is it recompiling the centOS kernel or what?Fullfaced
This worked for me, I'm using CENTOs 7, and Python 3.8.14. Thank you.Vargo
B
31

This is what I did to get it to work.

I am using pythonbrew(which is using pip) with python 2.7.5 installed.

I first did what Zubair(above) said and ran this command:

sudo apt-get install libsqlite3-dev

Then I ran this command:

pip install pysqlite

This fixed the database problem and I got confirmation of this when I ran:

python manager.py syncdb
Befuddle answered 2/11, 2013 at 23:40 Comment(4)
in Centos 6.5 run yum install sqlite-devel instead of the first line.Cyanogen
That's good for Python 2, but pysqlite is now sqlite3 in Python 3, and you can't pip -m install that.Satterwhite
pysqlite is not supported on Python 3. When using Python 3, use the sqlite3 module from the standard librarySile
@Befuddle I think it should be manage.py instead of manager.pyHebe
O
22

For Python 3.7.8 with Redhat 7 or Centos 7.

  • Install sqlite-devel
$ yum install sqlite-devel
  • Compile and install Python3 with sqllite extensions
$ ./configure --enable-optimizations --enable-loadable-sqlite-extensions
$ make install
Outspoken answered 16/10, 2020 at 8:21 Comment(2)
can confirm this works with 3.10.8Demonetize
This also worked on Amazon Linux 2 base image, thanks!Ontogeny
V
14

I found lots of people meet this problem because the Multi-version Python, on my own vps (cent os 7 x64), I solved it in this way:

  1. Find the file "_sqlite3.so"

    find / -name _sqlite3.so
    

    out: /usr/lib64/python2.7/lib-dynload/_sqlite3.so

  2. Find the dir of python Standard library you want to use,

    for me /usr/local/lib/python3.6/lib-dynload

  3. Copy the file:

    cp   /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.6/lib-dynload
    

Finally, everything will be ok.

Voss answered 18/4, 2017 at 11:51 Comment(4)
Didn't work for me. Got ImportError: dynamic module does not define module export function (PyInit__sqlite3) on CentOS 7.Nocuous
same to me, is that py2 .so can't be used for py3.6.4? @NocuousMabelmabelle
I got this error instead - ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directoryEffendi
Seems to work for me: sudo cp /usr/lib64/python3.6/lib-dynload/_sqlite3.cpython-36m-x86_64-linux-gnu.so /usr/local/lib/python3.7/lib-dynload/_sqlite3.so. Now I can run tensorboard without the _sqlite3 error! ThxPopsicle
C
11

My _sqlite3.so is in /usr/lib/python2.5/lib-dynload/_sqlite3.so. Judging from your paths, you should have the file /usr/local/lib/python2.5/lib-dynload/_sqlite3.so.

Try the following:

find /usr/local -name _sqlite3.so

If the file isn't found, something may be wrong with your Python installation. If it is, make sure the path it's installed to is in the Python path. In the Python shell,

import sys
print sys.path

In my case, /usr/lib/python2.5/lib-dynload is in the list, so it's able to find /usr/lib/python2.5/lib-dynload/_sqlite3.so.

Compulsory answered 31/7, 2009 at 4:50 Comment(6)
just checked. the path is in there, but _sqlite3.so is indeed missing. Any suggestions whether i can seperately install it or better to reinstall python? thx!Lenticular
It looks like you built and installed Python manually (are the packages in your OS too old?), since it's in /usr/local. Make sure that the sqlite dev package is installed (libsqlite3-dev in current distros, maybe not in yours), or Python won't be able to build the module. If you install it, you'll need to rebuild Python so it includes that module.Compulsory
Hmm, I installed libsqlite3-dev and rebuild python, but now i get anothe error: ImportError: ./_sqlite3.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8Lenticular
I'm confused. Your distro has Python 2.5 already (packages.debian.org/lenny/python2.5). Why are you building it yourself?Compulsory
ah, sorry, wrong choice of words. in fact i re-installed python2.5 via apt-get.Lenticular
But you're running Python out of /usr/local. It looks like you installed Python twice--once yourself and once with apt-get, and the one in /usr/local is broken.Compulsory
O
9

I recently tried installing python 2.6.7 on my Ubuntu 11.04 desktop for some dev work. Came across similar problems to this thread. I mamaged to fix it by:

  1. Adjusting the setup.py file to include the correct sqlite dev path. Code snippet from setup.py:

    def sqlite_incdir:
    sqlite_dirs_to_check = [
    os.path.join(sqlite_incdir, '..', 'lib64'),
    os.path.join(sqlite_incdir, '..', 'lib'),
    os.path.join(sqlite_incdir, '..', '..', 'lib64'),
    os.path.join(sqlite_incdir, '..', '..', 'lib'),
    '/usr/lib/x86_64-linux-gnu/'
    ]
    

    With the bit that I added being '/usr/lib/x86_64-linux-gnu/'.

  2. After running make I did not get any warnings saying the sqlite support was not built (i.e., it built correctly :P ), but after running make install, sqlite3 still did not import with the same "ImportError: No module named _sqlite3" whe running "import sqlite3".

    So, the library was compiled, but not moved to the correct installation path, so I copied the .so file (cp /usr/src/python/Python-2.6.7/build/lib.linux-x86_64-2.6/_sqlite3.so /usr/local/python-2.6.7/lib/python2.6/sqlite3/ — these are my build paths, you will probably need to adjust them to your setup).

Voila! SQLite3 support now works.

Odense answered 16/7, 2011 at 6:5 Comment(2)
Thank you! Just the first part was needed for Linux Mint Debian Edition, 2014Nonrepresentational
Thank you! Exactly same problem for me. The library is built but not copied to the right directory.Muhammadan
C
8

This worked for me in Redhat Centos 6.5:

yum install sqlite-devel
pip install pysqlite
Cyanogen answered 16/8, 2014 at 10:31 Comment(2)
just fyi I did not need to do the pip stepCacoepy
pip install pysqlite3-binary worked instead of pip install pysqlite3Richie
I
5

sqlite3 ships with Python. I also had the same problem, I just uninstalled python3.6 and installed it again.

Uninstall existing python:

sudo apt-get remove --purge python3.6

Install python3.6:

sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xvf Python-3.6.0.tar.xz
cd Python-3.6.0/
./configure
sudo make altinstall
Impignorate answered 18/7, 2018 at 11:15 Comment(1)
Works well on Debian BusterCoachandfour
C
4

Is the python-pysqlite2 package installed?

sudo apt-get install python-pysqlite2
Cullie answered 31/7, 2009 at 4:23 Comment(3)
sqlite is installed with Python; you don't need to install a separate package for it, and we can tell that he does already have the Python-supplied library. Installing python-sqlite would be confusing at best.Compulsory
Brain cramp. I meant the python-pysqlite2 package. I could not get Django/sqlite to work on lenny without this package. I've updated my answer.Cullie
I have python-pysqlite2 installed.Lenticular
H
4

Checking your settings.py file. Did you not just write "sqlite" instead of "sqlite3" for the database engine?

Highboy answered 20/10, 2009 at 15:29 Comment(0)
C
4

i got the same problem, nothing worked for me from the above ans but now i fixed it by

just remove python.pip and sqlite3 and reinstall

  1. sudo apt-get remove python.pip
  2. sudo apt-get remove sqlite3

now install it again

  1. sudo apt-get install python.pip
  2. sudo apt-get install sqlite3

in my case while installing sqlite3 again it showed some error then i typed

  1. sqlite3

on terminal to check if it was removed or not and it started unpacking it

once the sqlite3 is installed fireup terminal and write

  1. sqlite3
  2. database.db (to create a database) i'm sure this will definately help you
Colb answered 14/3, 2018 at 8:37 Comment(1)
Does not work on Ubuntu, Python 3.7.10, Jupyter 6.1.5Bradybradycardia
L
4

I had the same problem after installing Python 3.8.11 using asdf

To fix the issue:

I had to install libsqlite3-dev

sudo apt-get install libsqlite3-dev

Then uninstall Python via asdf

asdf uninstall python 3.8.11

And install Python again via asdf

asdf install python 3.8.11
Levant answered 14/10, 2021 at 3:54 Comment(0)
S
3

Putting answer for anyone who lands on this page searching for a solution for Windows OS:

You have to install pysqlite3 or db-sqlite3 if not already installed. you can use following to install.

  • pip install pysqlite3
  • pip install db-sqlite3

For me the issue was with DLL file of sqlite3.

Solution:

  1. I took DLL file from sqlite site. This might vary based on your version of python installation.

  2. I pasted it in the DLL directory of the env. for me it was "C:\Anaconda\Lib\DLLs", but check for yours. Before and After placing DLL file

Systematology answered 7/3, 2020 at 5:33 Comment(1)
I had the exact error. This somehow solved my problem. Thanks!Service
P
3

I was disappointed this issue still exist till today. As I have recently been trying to install vCD CLI on CentOS 8.1 and I was welcomed with the same error when tried to run it. The way I had to resolve it in my case is as follow:

  • Install SQLite3 from scratch with the proper prefix
  • Make clean my Python Installation
  • Run Make install to reinstall Python

As I have been doing this to create a different blogpost about how to install vCD CLI and VMware Container Service Extension. I have end up capturing the steps I used to fix the issue and put it in a separate blog post at:

http://www.virtualizationteam.com/cloud/running-vcd-cli-fail-with-the-following-error-modulenotfounderror-no-module-named-_sqlite3.html

I hope this helpful, as while the tips above had helped me get to a solution, I had to combine few of them and modify them a bit.

Persist answered 6/5, 2020 at 12:8 Comment(1)
Thank you for disclosing your affiliation with the link you are providing! It is appreciated.Corinnacorinne
D
3

The following worked for Python 3.9 with a virtual environment:

  1. Install the sqlite3 library.

    sudo apt-get install libsqlite3-dev
    
  2. Activate the Python virtual environment.

    source env/bin/activate
    
  3. Copy the sqlite3 file into the Python virtual environment and rename it to support Python 3.9.

    cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages
    mv ./env/lib/python3.9/site-packages/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages/_sqlite3.cpython-39-x86_64-linux-gnu.so
    

Note, we're renaming 38 to 39 in the file name to support Python 3.9.

Diplomatic answered 2/2, 2022 at 19:59 Comment(0)
H
2

I have the problem in FreeBSD 8.1:

- No module named _sqlite3 -

It is solved by stand the port ----------

/usr/ports/databases/py-sqlite3

after this one can see:

OK ----------
'>>>' import sqlite3 -----
'>>>' sqlite3.apilevel -----
'2.0'
Harney answered 29/8, 2011 at 23:40 Comment(3)
This answer makes very little sense. Can you revise it?Osrock
I had same issue, FreeBSD 8.2 w/Py2.7.2. Resolved by just running through make/install again, for py-sqlite3.Clock
you have to make deinstall if it seems installed at first. freebsd 10.2Kauslick
S
2

you must be in centos or redhat and compile python yourself, it is python‘s bug do this in your python source code dir and do this below

curl -sk https://gist.github.com/msabramo/2727063/raw/59ea097a1f4c6f114c32f7743308a061698b17fd/gistfile1.diff | patch -p1
Slump answered 7/1, 2014 at 3:13 Comment(0)
D
2

Try installing sqlite like this if you are using FreeBSD.

pkg install py27-sqlite3-2.7.10_6
Deflocculate answered 21/12, 2020 at 10:27 Comment(0)
H
1

I faced this issue with multiple python dependent package while setup in python virtual enironment in Ubuntu.It is because of sqlite binding for our python.

Error I got:

    from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'

I resolved it by --enable-loadable-sqlite-extensions=yes 1.) First find your python or python version you used for creating virtual env. I have used python3.8 e.g

$ whereis python
python: /usr/bin/python3.6m /usr/bin/python /usr/bin/python3.8 /usr/bin/python2.7-config /usr/bin/python3.8-config  python

$ cd /usr/bin

$ls
python3.8
python3.8-config

Note: there will be many package check for pytho. you will find configure file for each python version, now use specific python version

ox:/usr/bin$ ./python3.8-config --enable-loadable-sqlite-extensions=yes

OR

ox:/usr/bin$ ./python3.8-config --enable-optimizations --enable-loadable-sqlite-extensions

Now, create your virtual env using that python version e.g Go the folder where you want to create the virtual env

$ python3.8 -m venv mlwen_jup_env
$ source mlwen_jup_env/bin/activate

Its done, now you can install packages

Hebe answered 22/2, 2022 at 16:25 Comment(0)
V
1

I ran into this same problem on a NetBSD server. A missing .so file needed to be installed using pkgin. To identify what package to install, I ran

pkgin search sqlite

which had lots of results, including

...

py38-aiosqlite-0.17.0nb1  Async bridge to the standard sqlite3 module
py38-apsw-3.37.0nb2  Python wrapper for SQLite
py38-peewee-3.15.0   Small, expressive ORM for PostgreSQL, MySQL and SQLite
py38-sqlite3-3.8.13nb22  Built-in sqlite support for Python 2.5 and up
py39-aiosqlite-0.17.0nb1  Async bridge to the standard sqlite3 module
py39-apsw-3.37.0nb2  Python wrapper for SQLite
py39-peewee-3.15.0   Small, expressive ORM for PostgreSQL, MySQL and SQLite
py39-sqlite3-3.9.13nb22  Built-in sqlite support for Python 2.5 and up
...

(and other python versions as well). I'm using python 3.9, so py39-sqlite3-3.9.13nb22 was the correct choice in my case. Running

sudo pkgin install py39-sqlite3-3.9.13nb22

fixed the issue for me.

Varico answered 31/10, 2022 at 16:10 Comment(2)
pkgin: command not foundKilt
NetBSD does not necessarily come with pkgin preinstalled. This page has the official instructions for installing pkg_add and then pkgin: netbsd.org/docs/pkgsrc/using.htmlVarico
V
1

I resolved reinstalling Python pyenv install <version> and then pyenv rehash. Without destroying any previously created virtualenv

Veliger answered 5/9, 2023 at 8:9 Comment(0)
P
1

I am using Ubuntu with Python3.9 and a venv. I had the same issue. first I installed pysqlite

pip install pysqlite3

but it was installed in the /home/<user>/.local/lib/python3.9/site-packages/pysqlite3

then I moved it to the local dir

mv /home/<user>/.local/lib/python3.9/site-packages/pysqlite3 /usr/local/lib/python3.9/sqlite3

pay attention to the name change from pysqlite3 to sqlite3

Peridium answered 4/2, 2024 at 16:31 Comment(0)
C
0

Download sqlite3:

wget http://www.sqlite.org/2016/sqlite-autoconf-3150000.tar.gz

Follow these steps to install:

$tar xvfz sqlite-autoconf-3071502.tar.gz
$cd sqlite-autoconf-3071502
$./configure --prefix=/usr/local
$make install
Climacteric answered 18/10, 2016 at 11:27 Comment(1)
This question was asked in 2009 and was about Debian 5. sqlite3 is now available in the repos (since Wheezy) so there is no need to install it manually. I guess this is true for most distros as well.Comte
C
-3

You need to install pysqlite in your python environment:

    $ pip install pysqlite
Clip answered 20/9, 2013 at 8:25 Comment(0)
P
-4

Try copying _sqlite3.so so that Python can find it.

It should be as simple as:

cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/

Trust me, try it.

Personalism answered 2/9, 2018 at 1:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.