Question :
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?
Answer #1:
It seems your makefile didn’t include the appropriate .so
file. You can correct this problem with the steps below:
- Install
sqlite-devel
(orlibsqlite3-dev
on some Debian-based systems) - 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
.
Answer #2:
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.
Answer #3:
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.
Answer #4:
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
Answer #5:
-
Install the
sqlite-devel
package:yum install sqlite-devel -y
-
Recompile python from the source:
./configure make make altinstall
Answer #6:
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
Answer #7:
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.
Answer #8:
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
out:
/usr/lib64/python2.7/lib-dynload/_sqlite3.so
-
Find the dir of python Standard library you want to use,
for me
/usr/local/lib/python3.6/lib-dynload
-
Copy the file:
cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.6/lib-dynload
Finally, everything will be ok.