7

The sqlite3 module is included in Python version 2.5+. However, I am stuck with version 2.4. I uploaded the sqlite3 module files, added the directory to sys.path, but I get the following error when I try to import it:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "sqlite3/__init__.py", line 23, in ?
    from dbapi2 import *
  File "sqlite3/dbapi2.py", line 26, in ?
    from _sqlite3 import *
ImportError: No module named _sqlite3

The file '_sqlite3' is in lib-dynload, but if I include this in the sqlite3 directory, I get additional errors.

Any suggestions? I am working in a limited environment; I don't have access to GCC, among other things.

Tony
  • 2,955
  • 7
  • 26
  • 23
  • Install `libsqlite3-dev` Source: http://superuser.com/questions/122140/problem-with-installing-sqlite3-module-for-python-2-6-on-an-ubuntu-system – inakiabt Jan 04 '13 at 03:02

4 Answers4

13

I had same problem with CentOS and python 2.4

My solution:

yum install python-sqlite2

and try following python code

try:
    import sqlite3
except:
    from pysqlite2 import dbapi2 as sqlite3
  • One can install sqlite in Python 2.4 regardless of the Linux distribution with `easy_install pysqlite` (just take care not to mix your system packages with Python packages - i.e. just do the easy install in a virtualenv, or if the package does not exist for your linux). The import sequence on this answer is fine afterwards. – jsbueno Aug 07 '13 at 01:13
1

Did you install it? That often works better than messing with sys.path.

python setup.py install

If so, you should then find it.

If, for some reason, you can't install it, set the PYTHONPATH environment variable. Do not make a habit of messing with sys.path.

S.Lott
  • 384,516
  • 81
  • 508
  • 779
1

You will need to install pysqlite. Notice, however, that this absolutely does require a compiler, unless you can find binaries for it (and Python 2.4) on the net. Using the 2.5 binaries will not be possible.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • Since I don't have a compiler, this won't be possible. I was hoping that Python was more portable; I'll have to continue to interface with SQLite using the command line. – Tony Apr 25 '09 at 16:23
-2

You must ensure your sqlite, sqlite-devel, python-sqlite are installed correctly first and then recompile Python.

JJJ
  • 32,902
  • 20
  • 89
  • 102
  • 3
    You shouldn't have to recompile the Python install to fix this issue...simply reinstalling the sqlite, sqlite-devel, and python-sqlite should suffice. Unless, of course, you meant "run the script again". – CodeMouse92 Dec 04 '11 at 16:47