2

i'm tying to play with sqlite3 on my centos server but it reports always the same error (module installed)....

Python 2.7.3 (default, Jun 29 2012, 19:03:18) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] 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 "sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

on ubuntu and so on works fine.... any ideas of what i'm missing here?


i recompile the 2.7.3 again and it catch the sqlite3 libs well.

casperOne
  • 73,706
  • 19
  • 184
  • 253
Tony
  • 3,425
  • 10
  • 30
  • 46
  • Have you installed the `python-sqlite` module? – Ricardo Altamirano Jul 09 '12 at 11:25
  • 1
    This question might help: [http://stackoverflow.com/questions/789030/how-can-i-import-the-sqlite3-module-into-python-2-4][1] [1]: http://stackoverflow.com/questions/789030/how-can-i-import-the-sqlite3-module-into-python-2-4 – Idok Jul 09 '12 at 12:47
  • 1
    Well, those questions were for 2.4.... i recompile the 2.7.3 again and it catch the sqlite3 libs well. +1 for the search :) thanks. – Tony Jul 09 '12 at 12:50
  • 1
    If you found a solution, post it as an answer and accept it so others who find this question can see the solution as well. – Ricardo Altamirano Jul 09 '12 at 13:03
  • a self explanatory phrase : "i recompile the 2.7.3 again..." :) – Tony Jul 10 '12 at 15:11

4 Answers4

16

If you are under RHEL/centos 6, you can try this:

cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/
Wenbing Li
  • 12,289
  • 1
  • 29
  • 41
6

This will work for CentOS:

ln -s /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/

/usr/local/lib/python2.7/ is already on python's path. No need to duplicate the file or add the python's path.

quine
  • 982
  • 1
  • 12
  • 20
2

first find:

find / -name _sqlite3.so
/usr/usr/lib/python2.6/lib-dynload/_sqlite3.so
/usr/local/service/python2.7/lib/python2.7/lib-dynload/_sqlite3.so
/usr/lib64/python2.6/lib-dynload/_sqlite3.so

next

cp /usr/local/service/python2.7/lib/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/

this centso 6.5 python2.7.10

22too
  • 31
  • 4
0

If you're using Python 2.7.3 on a Red Hat 5 or CentOS 5 machine, there was a bug that prevented the SQLite modules from compiling properly when building Python from source; you should see an error message when running make. It's since been fixed in 2.7.4 so your best option is to upgrade.

If that's not possible, then there's a patch available. Here's the bug page and the patch.

austin
  • 5,816
  • 2
  • 32
  • 40