为什么我的 python 看不到 pysqlite?
我想要 Python 和 sqlite 之间有一个接口。两者都安装在机器上。我有旧版本的 Python (2.4.3)。因此,默认情况下不包含 pysqlite。首先,我尝试通过安装 pysqlite 来解决这个问题,但在这个方向上我没有成功。我解决该问题的第二次尝试是安装新版本的 Python。我没有机器的root权限。所以,我在本地安装了它。 Python的新版本是(2.6.2)。据我所知,这个版本默认应该包含 pysqlite (现在它被称为“sqlite3”,而不是以前的“pysqlite2”)。
但是,如果我输入:
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 *”时得到的错误消息不同:
回溯(最近一次调用最后一次):
文件“”,第 1 行,位于 导入错误:没有名为 blablabla 的模块
因此,python 看到了与 pysqlite 相关的内容,但仍然存在一些问题。有人可以帮我解决这个问题吗?
聚苯乙烯 我使用 CentOS 版本 5.3(最终版)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Windows 上,
_sqlite3.pyd
驻留在C:\Python26\DLLs
中。在 *nix 上,它应该位于类似于/usr/lib/python2.6/lib-dynload/_sqlite3.so
的路径下。您可能缺少该共享库,或者您的PYTHONPATH
设置不正确。既然你说你没有以超级用户身份安装,那么它可能是一个格式错误的路径;您可以手动让 Python 搜索
_sqlite3.so
的路径,但首选方法可能是更改
.bashrc
中的PYTHONPATH
或其他登录文件。On Windows,
_sqlite3.pyd
resides inC:\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 yourPYTHONPATH
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 doingbut the preferred approach would probably be to change
PYTHONPATH
in your.bashrc
or other login file.你有一个“slite3.py”(实际上它相当于一个包,
sqlite3/__init__.py
,所以import sqlite3
本身就很好,但是该模块依次尝试import _sqlite3
失败,因此找不到_sqlite3.so
它应该位于本地 Python 下的python2.6/lib-dynload
中。 root,并且应该指示 ld 它也有权从该目录加载动态库(通常通过在 .bashrc 中设置适当的环境变量)您有 lib-dynload 目录吗?您的 shell 提示符下是否包含字符串 LD(大写),即env|grep LD
?You have a "slite3.py" (actually its equivalent for a package,
sqlite3/__init__.py
, soimport sqlite3
per se is fine, BUT that module in turns tries toimport _sqlite3
and fails, so it's not finding_sqlite3.so
. It should be inpython2.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?