views:

593

answers:

2

I would like to have an interface between Python and sqlite. Both are installed on the machine. I had an old version of Python (2.4.3). So, pysqlite was not included by default. First, I tried to solve this problem by installing pysqlite but I did not succeed in this direction. My second attempt to solve the problem was to install a new version of Python. I do not have the root permissions on the machine. So, I installed it locally. The new version of Python is (2.6.2). As far as I know this version should contain pysqlite by default (and now it is called "sqlite3", not "pysqlite2", as before).

However, if I type:

from sqlite3 import *

I get:

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

It has to be noted, that the above error message is different from those which I get if I type "from blablabla import *":

Traceback (most recent call last):
File "", line 1, in ImportError: No module named blablabla

So, python see something related with pysqlite but still has some problems. Can anybody help me, pleas, with that issue?

P.S. I use CentOS release 5.3 (Final).

+1  A: 

On Windows, _sqlite3.pyd resides in C:\Python26\DLLs. On *nix, it should be under a path similar to /usr/lib/python2.6/lib-dynload/_sqlite3.so. Chances are that either you are missing that shared library or your PYTHONPATH is set up incorrectly.

Since you said you did not install as a superuser, it's probably a malformed path; you can manually have Python search a path for _sqlite3.so by doing

import sys
sys.path.append("/path/to/my/libs")

but the preferred approach would probably be to change PYTHONPATH in your .bashrc or other login file.

Mark Rushakoff
I have directory /home/verrtex/opt/lib/python2.6/sqlite3. In this directory I have the following files: dbapi2.py dbapi2.pyc dbapi2.pyo dump.py dump.pyc dump.pyo __init__.py __init__.pyc __init__.pyo
Verrtex
I changed the PYTHONPATH in .bashrc and .bash_profile. And I source these files. It does not help.
Verrtex
By the way, how I can find directory containing the pysqlite library? Which file should I search for? _sqlite3.so?
Verrtex
`_sqlite3.so` is indeed what you're missing. If you can't find it, you might need to reinstall -- chances are that if you do an install *from source*, you'll be very explicitly warned if a file can't be created or anything like that.
Mark Rushakoff
By the way I have /usr/lib64/libsqlite3.so.0, /usr/lib64/libsqlite3.so.0.8.6. Can it help? And what should I reinstall? Python? SQLite? Pysqlite?
Verrtex
Those won't *directly* help, because Python shared libraries require a specific entry point that the user libraries won't have. However, since you *do* have SQLite libs on the computer, you should be able to build *Python* from source, and `./configure` *should* detect the presence of SQLite and build a Python library against it. You might need to explicitly mention SQLite in the `./configure` options, I'm not sure.
Mark Rushakoff
+1  A: 

You have a "slite3.py" (actually its equivalent for a package, sqlite3/__init__.py, so import sqlite3 per se is fine, BUT that module in turns tries to import _sqlite3 and fails, so it's not finding _sqlite3.so. It should be in python2.6/lib-dynload under your local Python root, AND ld should be instructed that it has permission to load dynamic libraries from that directory as well (typically by setting appropriate environment variables e.g. in your .bashrc). Do you have that lib-dynload directory? What's in it? What environment variables do you have which contain the string LD (uppercase), i.e. env|grep LD at your shell prompt?

Alex Martelli
I have /home/verrtex/opt/lib/python2.6/lib-dynload but there is no *sql* files. "env | grep LD" tells me "OLDPWD=/home/verrtex/opt/lib/python2.6"
Verrtex
I wanted to say that in my /home/verrtex/opt/lib/python2.6/lib-dynload directory there are no files containing substring sql.
Verrtex