views:

3071

answers:

4

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?

A: 

Is the python-pysqlite2 package installed?

sudo apt-get install python-pysqlite2
bryan
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.
Glenn Maynard
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.
bryan
I have python-pysqlite2 installed.
Alexander van Dijk
+1  A: 

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.

Glenn Maynard
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!
Alexander van Dijk
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.
Glenn Maynard
Hmm, I installed libsqlite3-dev and rebuild python, but now i get anothe error: ImportError: ./_sqlite3.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8
Alexander van Dijk
I'm confused. Your distro has Python 2.5 already (http://packages.debian.org/lenny/python2.5). Why are you building it yourself?
Glenn Maynard
ah, sorry, wrong choice of words. in fact i re-installed python2.5 via apt-get.
Alexander van Dijk
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.
Glenn Maynard
+1  A: 

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

myselfhimself
+1  A: 

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.

Emilien