问题描述
我想要一个 Python 和 sqlite 之间的接口.两者都安装在机器上.我有一个旧版本的 Python (2.4.3).因此,默认情况下不包含 pysqlite.首先,我试图通过安装 pysqlite 来解决这个问题,但我在这个方向上没有成功.我解决该问题的第二次尝试是安装新版本的 Python.我在机器上没有 root 权限.所以,我在本地安装了它.Python 的新版本是 (2.6.2).据我所知,这个版本默认应该包含 pysqlite(现在它被称为sqlite3",而不是像以前一样的pysqlite2").
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).
但是,如果我输入:
from sqlite3 import *
我明白了:
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
必须注意的是,上述错误信息与我输入from blablabla import *"时得到的信息不同:
It has to be noted, that the above error message is different from those which I get if I type "from blablabla import *":
回溯(最近一次调用最后一次):
文件",第 1 行,在导入错误:没有名为 blablabla 的模块
所以,python 看到了一些与 pysqlite 相关的东西,但仍然存在一些问题.任何人都可以帮我解决这个问题吗?
So, python see something related with pysqlite but still has some problems. Can anybody help me, pleas, with that issue?
附言我使用 CentOS 5.3 版(最终版).
P.S.I use CentOS release 5.3 (Final).
推荐答案
在 Windows 上,_sqlite3.pyd
驻留在 C:\Python26\DLLs
代码>.在 *nix 上,它应该在类似于 /usr/lib/python2.6/lib-dynload/_sqlite3.so
的路径下.可能是您缺少该共享库,或者您的 PYTHONPATH
设置不正确.
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")
但首选方法可能是更改 .bashrc
或其他登录文件中的 PYTHONPATH
.
but the preferred approach would probably be to change PYTHONPATH
in your .bashrc
or other login file.
这篇关于为什么我的python看不到pysqlite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!