如何将 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 20:52:08  来源:igfitidea点击:

How can I import the sqlite3 module into Python 2.4?

pythonsqlite

提问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 PYTHONPATHenvironment variable. Do not make a habit of messing with sys.path.

如果由于某种原因无法安装它,请设置PYTHONPATH环境变量。不要养成乱搞的习惯sys.path

回答by Martin v. L?wis

You will need to install pysqlite. Notice, however, that this absolutely does require a compiler, unless you can find binaries for it (and Python 2.4) on the net. Using the 2.5 binaries will not be possible.

您将需要安装pysqlite。但是请注意,这绝对需要编译器,除非您可以在网上找到它的二进制文件(和 Python 2.4)。将无法使用 2.5 二进制文件。

回答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。