Python – How to make Python see sqlite

pysqlitepythonsqlite

I cannot use sqlite3 (build python package), for the reason that _sqlite3.so file is missing. I found that people had the same problem and they resolved it here. To solve my problem I have to "install sqlite3 and recompile Python". I also found out that the problem can be solved by "building from source and moving the library to /usr/lib/python2.5/lib-dynload/".

As I have been told to here, I have to install sqlite from the source and copy newly compiled files to my Python directory (nothing was said about "recompile Python"). Well, I have installed sqlite and now I have to copy something to my /lib-dynload/ directory.

I am not sure what exactly I should copy. In my /lib-dynload/ directory I have only .so files. And in my sqlite-3.6.18 I do not have any *.so files (it makes me suspicious). I had this problem since I did not have _sqlite3.so file in /lib-dynload/. By compilation of sqlite I got some new files (for example sqlite3.o and sqlite3.lo) but not _sqlite3.so.

P.S. Some details:

1. I use Python 2.6.2 (which I installed locally).

2. I do not have root permissions.

3. I had already sqlite installed globally on the machine by root.

4. I just installed sqlite locally.

5. My OS is CentOS release 5.3 (Final).

6. When I type in Python command line import sqlite3 I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/loctopu/opt/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/home/loctopu/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

Best Answer

I don't have exact answer, but few hints here

  • To install python from source, you don't need to be root, you can always install at /home/USERNAME/usr, for example when you do configure, do like ./configure --prefix=/home/USERNAME/usr

  • Installing sqlite binaries does not mean its included python extension (instead, sqlite dev files are needed when you compile python)

  • proper import usage of sqlite3 is import sqlite3