Ray*_*orn 5 python sqlite conda
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.
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'
Run Code Online (Sandbox Code Playgroud)
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.
On the Homebrew Github, there was a related issue, where someone suggested checking whether the missing symbol was there. 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
Run Code Online (Sandbox Code Playgroud)
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. 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.
Does the conda distribution attempt to link to the system libsqlite? If so, why does this problem not affect the py39 environment?
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.
根据@merv的建议,这个问题的解决方案是强制重新安装软件包libsqlite。
$ mamba install libsqlite --force-reinstall
Run Code Online (Sandbox Code Playgroud)
更新 Python 后,似乎sqlite3链接到了 Mac 系统库,/usr/lib/libsqlite3.dylib而不是 conda-forge 安装的库。根据其他地方的讨论,苹果很可能_sqlite3_enable_load_extension出于安全原因禁用了缺失的扩展,从而导致了观察到的错误消息。我不知道为什么会首先发生链接错误,但幸运的是,condalibsqlite作为单独的包分发,因此修复很容易实现。