You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu Focal系统自带Python3无法导入sqlite3的问题咨询

Hey there! Let's break down why this is happening with your system-provided Python 3.8.5 on Ubuntu Focal, and how to fix it without reinstalling Python.

Root Cause

The undefined symbol: sqlite3_errstr error tells us that Python's _sqlite3 extension can't find a specific SQLite function it needs. Here's the key context: sqlite3_errstr is a function that was added in SQLite 3.32.0, but Ubuntu Focal's default system SQLite version is 3.31.1.

Since you're using the pre-installed Python, this mismatch usually happens because:

  • Your system's SQLite library was modified (e.g., you installed a newer version via a PPA then rolled back, or a manual installation left conflicting files)
  • The python3-sqlite3 package got corrupted, causing it to reference a function that doesn't exist in your current system SQLite.

Fixes to Try (No Python Reinstall Needed)

1. Confirm Your SQLite Version

First, double-check what SQLite version your system is running:

sqlite3 --version

If the output shows 3.31.1 or older, that's the version mismatch we suspected.

2. Reinstall System SQLite and Python SQLite Packages

Since we're dealing with system-provided software, the safest first step is to repair the relevant packages:

sudo apt update
sudo apt install --reinstall libsqlite3-dev python3-sqlite3

This will refresh the SQLite development library and Python's sqlite3 bindings, ensuring they're properly aligned with your system's default versions.

3. Check for Library Path Conflicts

Sometimes manually installed SQLite libraries can override the system's default one. Run this to see which SQLite library Python's _sqlite3 is trying to use:

ldd /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so | grep sqlite3

If the output points to a path that's not /usr/lib/x86_64-linux-gnu/libsqlite3.so.0, you've got a conflicting library. Test if fixing the path resolves the issue:

LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu ipython

If IPython works normally here, you'll need to remove the conflicting third-party SQLite library or adjust your system's library load order.

4. Repair System Package Dependencies

If the above steps don't work, there might be a broader package dependency issue. Run these commands to fix broken packages:

sudo apt --fix-broken install
sudo dpkg --configure -a

Quick Summary

This isn't a problem with your system Python itself—it's a misalignment between the SQLite functions Python expects and what your system's SQLite library provides. Reinstalling the relevant system packages or resolving library conflicts should get IPython's history working again without touching your pre-installed Python.

内容的提问来源于stack exchange,提问作者Eurydice

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 16:02:48