如何将sqlite3模块导入Python 2.4?

时间:2022-05-02 00:16:18

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。

4 个解决方案

#1


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

#2


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的习惯。

#3


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二进制文件是不可能的。

#4


You must ensure your sqlite, sqlite-devel, python-sqlite are installed correctly first and then recompile Python.

您必须首先正确安装sqlite,sqlite-devel,python-sqlite,然后重新编译Python。

#1


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

#2


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的习惯。

#3


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二进制文件是不可能的。

#4


You must ensure your sqlite, sqlite-devel, python-sqlite are installed correctly first and then recompile Python.

您必须首先正确安装sqlite,sqlite-devel,python-sqlite,然后重新编译Python。