简体   繁体   English

sqlite3 损坏时如何修复 Mac base conda 环境

[英]How to fix a Mac base conda environment when sqlite3 is broken

I recently updated the Python version of my base conda environment from 3.8 to 3.9, using mamba update python=3.9 , but I can no longer run IPython, because the sqlite3 package appears to be broken.我最近使用mamba update python=3.9将我的基本 conda 环境的 Python 版本从 3.8 更新到 3.9,但我无法再运行 IPython,因为 sqlite3 包似乎已损坏。

python
Python 3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:55:37) 
[Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rosborn/opt/miniconda3/lib/python3.9/sqlite3/__init__.py", line 57, in <module>
    from sqlite3.dbapi2 import *
  File "/Users/rosborn/opt/miniconda3/lib/python3.9/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: dlopen(/Users/rosborn/opt/miniconda3/lib/python3.9/lib-dynload/_sqlite3.cpython-39-darwin.so, 0x0002): Symbol not found: (_sqlite3_enable_load_extension)
  Referenced from: '/Users/rosborn/opt/miniconda3/lib/python3.9/lib-dynload/_sqlite3.cpython-39-darwin.so'
  Expected in: '/usr/lib/libsqlite3.dylib'

Since I had another Python 3.9 environment that is still functional, I tried copying over the envs/py39/lib/sqlite3.36.0 and envs/py39/lib/python3.9/sqlite3 directories, as well as envs/py39/lib/python3.9/lib-dynload/_sqlite3.cpython-39-darwin.so because I assumed the sqlite3 libraries had been incorrectly compiled, but that doesn't fix the problem.由于我有另一个仍然可用的 Python 3.9 环境,我尝试复制envs/py39/lib/sqlite3.36.0envs/py39/lib/python3.9/sqlite3目录,以及envs/py39/lib/python3.9/lib-dynload/_sqlite3.cpython-39-darwin.so因为我假设 sqlite3 库编译不正确,但这并不能解决问题。

On the Homebrew Github, there was a related issue , where someone suggested checking whether the missing symbol was there.在 Homebrew Github 上,有一个相关的问题,有人建议检查是否有丢失的符号。 It seems to be all present and correct.它似乎全部存在且正确。

$ nm -gj /Users/rosborn/opt/miniconda3/lib/python3.9/lib-dynload/_sqlite3.cpython-39-darwin.so | grep enable_load_extension 
_sqlite3_enable_load_extension

I don't know how Homebrew installs sqlite3, but the remaining fixes seemed to require checking the system libsqlite, which I don't have administrative access to.我不知道 Homebrew 如何安装 sqlite3,但其余修复似乎需要检查系统 libsqlite,我没有管理权限。 In case it's relevant, I am on an Intel Mac, so it's not related to the M1 chip, as some related issues appear to be.如果它是相关的,我使用的是 Intel Mac,所以它与 M1 芯片无关,因为一些相关问题似乎是这样。

Does the conda distribution attempt to link to the system libsqlite? conda 发行版是否尝试链接到系统 libsqlite? If so, why does this problem not affect the py39 environment?如果是,为什么这个问题不影响py39环境?

Any tips will be welcome.欢迎任何提示。 If it were not the base environment, I would just delete the one with the problem and start again.如果不是基础环境,我就把有问题的删掉,重新开始。 I attempted a forced reinstall of sqlite3, but it appeared not to be installable as a separate package.我尝试强制重新安装 sqlite3,但它似乎不能作为单独的包安装。

Following the suggestions by @merv, the solution to this problem was to force a reinstall of the libsqlite package.根据@merv 的建议,此问题的解决方案是强制重新安装libsqlite包。

$ mamba install libsqlite --force-reinstall

After updating Python, it seems that sqlite3 was linked to the Mac system library, /usr/lib/libsqlite3.dylib , rather than one installed by conda-forge.更新 Python 后, sqlite3似乎链接到 Mac 系统库/usr/lib/libsqlite3.dylib ,而不是 conda-forge 安装的库。 According to discussions elsewhere , it is likely that Apple disables the missing _sqlite3_enable_load_extension extension for security reasons, leading to the observed error message.根据其他地方的讨论,Apple 可能出于安全原因禁用了缺少的_sqlite3_enable_load_extension扩展,从而导致出现观察到的错误消息。 I don't know why the link error occurred in the first place, but fortunately, conda distributes libsqlite as a separate package, so the fix was simple to implement.我不知道为什么首先会出现链接错误,但幸运的是,conda 将libsqlite作为一个单独的包分发,因此修复很容易实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM