我怎样才能让Python看到sqlite?

发布于 2024-08-06 18:39:33 字数 1378 浏览 6 评论 0原文

我无法使用 sqlite3(构建 python 包),因为 _sqlite3.so 文件丢失。我发现人们有同样的问题,他们解决了它 此处。为了解决我的问题,我必须“安装 sqlite3 并重新编译 Python”。我还发现可以通过“从源代码构建并将库移动到 /usr/lib/python2.5/lib-dynload/”来解决该问题。

正如我被告知的那样,我必须从源安装 sqlite 并将新编译的文件复制到我的 Python 目录(没有提到“重新编译 Python”)。好吧,我已经安装了 sqlite,现在我必须将一些内容复制到我的 /lib-dynload/ 目录中。

我不确定我到底应该复制什么。在我的 /lib-dynload/ 目录中,我只有 .so 文件。在我的 sqlite-3.6.18 中,我没有任何 *.so 文件(这让我很怀疑)。我遇到这个问题是因为我在 /lib-dynload/ 中没有 _sqlite3.so 文件。通过编译 sqlite,我得到了一些新文件(例如 sqlite3.osqlite3.lo),但不是 _sqlite3.so

PS一些细节:
1.我使用Python 2.6.2(我在本地安装的)。
2。我没有root权限。
3。我已经通过root在机器上全局安装了sqlite。
4。我刚刚在本地安装了sqlite。
5。我的操作系统是 CentOS 版本 5.3(最终版)。
6。当我在 Python 命令行中输入 import sqlite3 时,我得到:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/loctopu/opt/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/home/loctopu/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

I cannot use sqlite3 (build python package), for the reason that _sqlite3.so file is missing. I found that people had the same problem and they resolved it here. To solve my problem I have to "install sqlite3 and recompile Python". I also found out that the problem can be solved by "building from source and moving the library to /usr/lib/python2.5/lib-dynload/".

As I have been told to here, I have to install sqlite from the source and copy newly compiled files to my Python directory (nothing was said about "recompile Python"). Well, I have installed sqlite and now I have to copy something to my /lib-dynload/ directory.

I am not sure what exactly I should copy. In my /lib-dynload/ directory I have only .so files. And in my sqlite-3.6.18 I do not have any *.so files (it makes me suspicious). I had this problem since I did not have _sqlite3.so file in /lib-dynload/. By compilation of sqlite I got some new files (for example sqlite3.o and sqlite3.lo) but not _sqlite3.so.

P.S. Some details:

1. I use Python 2.6.2 (which I installed locally).

2. I do not have root permissions.

3. I had already sqlite installed globally on the machine by root.

4. I just installed sqlite locally.

5. My OS is CentOS release 5.3 (Final).

6. When I type in Python command line import sqlite3 I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/loctopu/opt/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/home/loctopu/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懵少女 2024-08-13 18:39:33

我没有确切的答案,但这里有一些提示

  • 要从源代码安装python,你不需要是root,你可以随时安装在/home/USERNAME/usr,例如例如,当您进行配置时,请执行 ./configure --prefix=/home/USERNAME/usr

  • 安装 sqlite 安装sqlite二进制文件并不意味着它包含了python扩展(相反,编译python时需要sqlite dev文件)

  • sqlite3 的正确导入用法是 import sqlite3

I don't have exact answer, but few hints here

  • To install python from source, you don't need to be root, you can always install at /home/USERNAME/usr, for example when you do configure, do like ./configure --prefix=/home/USERNAME/usr

  • Installing sqlite binaries does not mean its included python extension (instead, sqlite dev files are needed when you compile python)

  • proper import usage of sqlite3 is import sqlite3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文