No module named _sqlite3
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
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 " ", line 1, in File "/usr/local/lib/python2.5/sqlite3/__init__.py", line 24, in from dbapi2 import * File "/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27, in 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?
It seems your makefile didn’t include the appropriate
.so file. You can correct this problem with the steps below:
libsqlite3-devon some Debian-based systems)
- Re-configure and re-compiled Python with
./configure --enable-loadable-sqlite-extensions && make && sudo make install
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.
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.
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.
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
yum install sqlite-devel -y
Recompile python from the source:
./configure make make altinstall
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.
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:
Find the file “_sqlite3.so”
find / -name _sqlite3.so
Find the dir of python Standard library you want to use,
Copy the file:
cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.6/lib-dynload
Finally, everything will be ok.
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:
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/’.
After running make I did not get any warnings saying the sqlite support was not built (i.e., it built correctly 😛 ), 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
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.
This worked for me in Redhat Centos 6.5:
yum install sqlite-devel pip install pysqlite
I have the problem in FreeBSD 8.1:
- No module named _sqlite3 -
It is solved by stand the port ———-
after this one can see:
OK ---------- '>>>' import sqlite3 ----- '>>>' sqlite3.apilevel ----- '2.0'
my python is build from source, the cause is missing options when exec configure
./configure --enable-loadable-sqlite-extensions --enable-optimizations make make install
Checking your settings.py file.
Did you not just write “sqlite” instead of “sqlite3” for the database engine?
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
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
Is the python-pysqlite2 package installed?
sudo apt-get install python-pysqlite2
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport