読者です 読者をやめる 読者になる 読者になる

python2.6の標準モジュールであるはずのsqlite3をimportしたらエラーになる場合の対処法

上の二つを参考にsqlite3つかってpythonだ!と思って実行したら下記のメッセージ。

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

ぐぐっても「これだ!」という解決法が絞れない。標準のモジュールじゃなかったの…?
ここはしっかりREADEMEでも読むかということで開いてみると

    753 Building the sqlite3 module
    754 ---------------------------
    755
    756 To build the sqlite3 module, you'll need the sqlite3 or libsqlite3
    757 packages installed, including the header files. Many modern operating
    758 systems distribute the headers in a separate package to the library -
    759 often it will be the same name as the main package, but with a -dev or
    760 -devel suffix.
    761
    762 The version of pysqlite2 that's including in Python needs sqlite3 3.0.8
    763 or later. setup.py attempts to check that it can find a correct version.

というわけで

#yum install sqlite-*
=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 sqlite-devel            i386       3.3.6-2          base              257 k

Transaction Summary
=============================================================================

で、もう一回makeやりなおしたらうまくいきましたとさ。
ぐぐる前に読むべきだったなー