如何将 sqlite3 模块导入 Python 2.4?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/789030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I import the sqlite3 module into Python 2.4?
提问by Tony
The sqlite3 module is included in Python version 2.5+. However, I am stuck with version 2.4. I uploaded the sqlite3 module files, added the directory to sys.path, but I get the following error when I try to import it:
sqlite3 模块包含在 Python 2.5+ 版中。但是,我坚持使用 2.4 版。我上传了 sqlite3 模块文件,将目录添加到 sys.path,但是当我尝试导入它时出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "sqlite3/__init__.py", line 23, in ?
from dbapi2 import *
File "sqlite3/dbapi2.py", line 26, in ?
from _sqlite3 import *
ImportError: No module named _sqlite3
The file '_sqlite3' is in lib-dynload, but if I include this in the sqlite3 directory, I get additional errors.
文件“_sqlite3”在 lib-dynload 中,但如果我将其包含在 sqlite3 目录中,则会出现其他错误。
Any suggestions? I am working in a limited environment; I don't have access to GCC, among other things.
有什么建议?我在有限的环境中工作;我无权访问 GCC,等等。
回答by
I had same problem with CentOS and python 2.4
我在 CentOS 和 python 2.4 上遇到了同样的问题
My solution:
我的解决方案:
yum install python-sqlite2
and try following python code
并尝试遵循 python 代码
try:
import sqlite3
except:
from pysqlite2 import dbapi2 as sqlite3
回答by S.Lott
Did you install it? That often works better than messing with sys.path
.
你安装了吗?这通常比搞乱sys.path
.
python setup.py install
If so, you should then find it.
如果是这样,那么您应该找到它。
If, for some reason, you can't install it, set the PYTHONPATH
environment variable. Do not make a habit of messing with sys.path
.
如果由于某种原因无法安装它,请设置PYTHONPATH
环境变量。不要养成乱搞的习惯sys.path
。
回答by Martin v. L?wis
回答by syshack
You must ensure your sqlite, sqlite-devel, python-sqlite are installed correctly first and then recompile Python.
您必须首先确保您的 sqlite、sqlite-devel、python-sqlite 安装正确,然后重新编译 Python。