【问题标题】:Shared library _sqlite3.so not found when importing sqlite3 on Python 2.6.6在 Python 2.6.6 上导入 sqlite3 时找不到共享库 _sqlite3.so
【发布时间】:2012-09-12 09:58:42
【问题描述】:

好吧,我已经为此奋斗了 2 天,这通常意味着它太容易实现了。

我有一个嵌入式 linux 系统,我在我的 ubuntu 上进行交叉编译。编译python时,sqlite3不在无法编译的模块列表中。

但是,_sqlite3.so 库与例如 json.so 和 ctypes.so array.so 不在同一位置... 在 Python-2.6.6/build/lib.linux868-2.6/

具有 init-functions 等的实际模块位于正确的位置: 在 Python-2.6.6/modules 中,也可以在目标系统上找到。

由于 so 文件丢失,我尝试使用我的 arm 编译器将它自己编译为共享库。这也不起作用。

无需手动编译so-file:

>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "rootfs/python/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
  File "rootfs/python/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
ImportError: /python/lib/python2.6/lib-dynload/_sqlite3.so: cannot open shared object file: No such file or directory

使用在 lib-dynloads 中找到的已编译共享库:

>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "rootfs/python/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
  File "rootfs/python/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
ImportError: dynamic module does not define init function (init_sqlite3)

编辑: 我想知道我是否为 sqlite3 编译了正确的库。据我现在了解 _sqlite3.so 是 python 构建器制作的东西,而 libsqlite3.so 是它需要构建它的库吗? libsqlite3.so 是从 Sqlite3 源代码构建的。我是不是搞错了?

任何拥有更多嵌入式 Linux 或 Python 经验的人都知道我在这里做错了什么?

【问题讨论】:

    标签: python sqlite embedded-linux python-2.6 dynamic-library


    【解决方案1】:

    尝试先在你的系统上编译和安装 sqlite3,然后编译 python。或者只是

    easy_install pysqlite
    

    【讨论】:

    • 我的系统是指嵌入式系统还是主机系统?无论如何,目前,我在我的主机系统上使用 sqlite3,包括开发文件。在目标系统上,我在构建 python 之前构建了 sqlite3,并且我已将虚拟文件系统的安装目录包含到 sqlite 模块编译搜索目录中。我得看看那个easy_install是否可以在makefile上使用。
    • 是的,我先把 sqlite3 安装在目录结构上,然后再放到 system.img 中
    • 如果你的 sqlite3 和它的 dev 文件已经放在你的目标系统的默认搜索路径中,python 应该默认启用模块 sqlite。但是,如果这对您不起作用,请尝试 easy_istall 方式,甚至自己编译 pysqlite3。
    • 就像我在回溯中的 code-sn-ps 一样,实际模块已启用,但在导入期间,它在动态库导入时崩溃
    【解决方案2】:

    好的,想通了。不知何故,我没有正确手动编译 SO 文件。让它像这样工作:

    首先从 setup.py 开始,我添加了为 sqlite3 模块启用的详细调试。这添加了一个解决问题的打印输出:

    skipping incompatible /usr/lib/libsqlite3.so
    cannot find -sqlite3
    

    这让我意识到 setup.py 选择了找到任何名为 sqlite3 的模块的第一条路径,而忽略了它的架构。从 setup.py 中删除其他搜索路径,但我有 ARM 编译库的路径,使它工作。 _sqlite3.so 与所有其他模块一起编译得很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-13
      • 1970-01-01
      • 2015-11-24
      • 2022-12-03
      • 1970-01-01
      • 2019-04-07
      • 2013-10-27
      • 1970-01-01
      相关资源
      最近更新 更多