Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
806 views
in Technique[技术] by (71.8m points)

sqlite - Why my python does not see pysqlite?

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 "<stdin>", line 1, in <module>  
  File "/home/verrtex/opt/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/home/verrtex/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
    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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

On Windows, _sqlite3.pyd resides in C:Python26DLLs. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...