安装sqlite-devel
yum -y install sqlite-devel
或者
dnf install sqlite-devel
一、Errors during downloading metadata
alinux3-module 0.0 B/s | 0 B 02:00 Errors during downloading metadata for repository 'alinux3-module': - Curl error (28): Timeout was reached for http://mirrors.aliyun.com/alinux/3/module/x86_64/repodata/repomd.xml Connection timed out after 30000 milliseconds Error: Failed to download metadata for repo 'alinux3-module': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried root@zw801e-ppu-02 allin-llm-ops-microservice# yum -y install sqlite-devel alinux3-module 0.0 B/s | 0 B 02:00 Errors during downloading metadata for repository 'alinux3-module': - Curl error (28): Timeout was reached for http://mirrors.aliyun.com/alinux/3/module/x86_64/repodata/repomd.xml Connection timed out after 30001 milliseconds - Curl error (28): Timeout was reached for http://mirrors.aliyun.com/alinux/3/module/x86_64/repodata/repomd.xml Connection timed out after 30000 milliseconds Error: Failed to download metadata for repo 'alinux3-module': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
问题不是 sqlite-devel 包不存在,而是 Alinux 3 的 yum/dnf 仓库 alinux3-module 元数据下载失败:
Curl error (28): Timeout was reached
http://mirrors.aliyun.com/alinux/3/module/x86_64/repodata/repomd.xml
也就是机器访问阿里云镜像超时
可以按下面步骤处理
1. 先确认网络访问镜像是否正常
执行:
curl -I http://mirrors.aliyun.com/alinux/3/module/x86_64/repodata/repomd.xml
如果卡住或超时,就是网络/DNS/出口问题
测试 DNS:
ping mirrors.aliyun.com
测试 HTTP:
curl -v http://mirrors.aliyun.com
2. 临时跳过 alinux3-module 仓库安装
如果只是安装 sqlite-devel:
dnf --disablerepo=alinux3-module install sqlite-devel
或者:
yum --disablerepo=alinux3-module install sqlite-devel
3. 清理 yum 缓存重新生成
dnf clean all
rm -rf /var/cache/dnf
dnf makecache
然后:
dnf install sqlite-devel
4. 检查 repo 配置
查看:
ls -l /etc/yum.repos.d/
找到:
grep -R "alinux3-module" /etc/yum.repos.d/
一般会看到:
/etc/yum.repos.d/alinux.repo
查看:
cat /etc/yum.repos.d/alinux.repo
5. 修改镜像地址(推荐)
如果当前:
baseurl=http://mirrors.aliyun.com/alinux/3/module/x86_64/
换 HTTPS:
baseurl=https://mirrors.aliyun.com/alinux/3/module/x86_64/
例如:
sed -i 's#http://mirrors.aliyun.com#https://mirrors.aliyun.com#g' \
/etc/yum.repos.d/*.repo
然后:
dnf clean all
dnf makecache
6. 如果服务器没有公网出口
很多生产服务器(尤其 K8s 节点/GPU节点)没有公网,会出现这种情况
检查:
ip route
看是否有默认路由:
应该有:
default via x.x.x.x dev eth0
测试:
curl -I https://www.baidu.com
如果失败:
需要:
- 配置 NAT 出口
- 配置 HTTP/HTTPS proxy
- 使用内部 yum mirror
7. 离线安装 sqlite-devel
如果机器不能联网,可以在有网络机器下载:
dnf download sqlite-devel
或者:
yum install --downloadonly --downloaddir=/tmp/sqlite sqlite-devel
然后复制 RPM:
scp sqlite-devel*.rpm root@目标服务器:/tmp/
安装:
rpm -ivh sqlite-devel*.rpm
8. Python 3.13 编译场景额外提醒
你前面是在:
/usr/local/python-3.13.5
环境安装 Python
如果你是重新编译 Python,sqlite-devel 是必须的,否则:
import sqlite3
会失败
安装后重新编译 Python:
./configure \
--prefix=/usr/local/python-3.13.5 \
--enable-optimizations
make -j$(nproc)
make install
验证:
/usr/local/python-3.13.5/bin/python3.13 -c "import sqlite3;print(sqlite3.sqlite_version)"
建议先执行:
dnf --disablerepo=alinux3-module install sqlite-devel
二、Connection timed out after 30000 milliseconds
yum --disablerepo=alinux3-module install sqlite-devel alinux3-updates 0.0 B/s | 0 B 02:00 Errors during downloading metadata for repository 'alinux3-updates': - Curl error (28): Timeout was reached for http://mirrors.aliyun.com/alinux/3/updates/x86_64/repodata/repomd.xml Connection timed out after 30000 milliseconds Error: Failed to download metadata for repo 'alinux3-updates': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
现在可以确定:不是单个 repo 问题,而是整个 Alinux 3 仓库访问失败
禁用了:
--disablerepo=alinux3-module
但是又卡在:
alinux3-updates
http://mirrors.aliyun.com/alinux/3/updates/x86_64/
Curl error (28): Timeout
说明服务器访问 mirrors.aliyun.com 超时
方案1:先测试网络(推荐先做)
执行:
curl -I --connect-timeout 5 http://mirrors.aliyun.com
再测试 IP:
ping mirrors.aliyun.com
查看 DNS:
cat /etc/resolv.conf
如果这里都超时,yum 无法解决,需要处理网络出口
方案2:切换 HTTPS 镜像地址
很多环境 HTTP 访问被限制,改 HTTPS:
sed -i 's#http://mirrors.aliyun.com#https://mirrors.aliyun.com#g' \
/etc/yum.repos.d/*.repo
清缓存:
yum clean all
rm -rf /var/cache/yum /var/cache/dnf
重新生成:
yum makecache
测试:
yum install sqlite-devel
方案3:临时禁用所有 updates/module,只用 base
查看 repo:
yum repolist all
可能看到:
alinux3-base
alinux3-updates
alinux3-module
尝试:
yum --disablerepo="*" \
--enablerepo=alinux3-base \
install sqlite-devel
方案4:检查 repo 配置
执行:
grep -R "mirrors.aliyun.com" /etc/yum.repos.d/
大概率:
[alinux3-updates]
name=alinux3 updates
baseurl=http://mirrors.aliyun.com/alinux/3/updates/x86_64/
enabled=1
修改:
vi /etc/yum.repos.d/alinux.repo
改:
baseurl=https://mirrors.aliyun.com/alinux/3/updates/x86_64/
方案5:如果服务器没有公网出口(生产环境常见)
检查:
ip route
需要类似:
default via 10.x.x.x dev eth0
测试:
curl -I https://www.baidu.com
如果:
curl: (28) Connection timed out
说明:
- 无公网 NAT
- 防火墙限制
- 安全组限制
- 出口代理缺失
这种情况下 yum 源换什么都没用
方案6:离线安装 sqlite-devel(最快)
在一台能联网的 Alinux 3机器:
yum install --downloadonly \
--downloaddir=/tmp/sqlite \
sqlite-devel
得到:
sqlite-devel-*.rpm
sqlite-libs-*.rpm
sqlite-*.rpm
复制:
scp /tmp/sqlite/*.rpm root@zw801e-ppu-01:/tmp/
目标机:
rpm -Uvh /tmp/*.rpm
另外确认系统版本
可以根据:
cat /etc/os-release
以及:
curl -v --connect-timeout 5 http://mirrors.aliyun.com
可以判断是:
- Alinux repo 地址问题
- DNS问题
- 服务器无公网出口
- 阿里云镜像 HTTP 被阻断
然后给对应修复方案
三、rpm -ivh sqlite-rpm/sqlite-devel-3.46.1-5.el10_1.x86_64.rpm报错
warning: sqlite-rpm/sqlite-devel-3.46.1-5.el10_1.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID c2a1e572: NOKEY error: Failed dependencies: sqlite(x86-64) = 3.46.1-5.el10_1 is needed by sqlite-devel-3.46.1-5.el10_1.x86_64
你的离线安装包缺少依赖:
error: Failed dependencies:
sqlite(x86-64) = 3.46.1-5.el10_1 is needed by sqlite-devel-3.46.1-5.el10_1.x86_64
说明:
你安装的是:
sqlite-devel-3.46.1-5.el10_1.x86_64.rpm
但是它依赖对应版本的:
sqlite-3.46.1-5.el10_1.x86_64.rpm
sqlite-devel 只是开发头文件包,需要 sqlite 主包
1. 查看你当前目录有哪些 rpm
执行:
ls -lh sqlite-rpm/
应该至少需要:
sqlite-3.46.1-5.el10_1.x86_64.rpm
sqlite-devel-3.46.1-5.el10_1.x86_64.rpm
sqlite-libs-3.46.1-5.el10_1.x86_64.rpm
2. 一起安装(推荐)
如果三个包都有:
rpm -Uvh sqlite-rpm/sqlite*.rpm
或者:
rpm -ivh \
sqlite-rpm/sqlite-libs-3.46.1-5.el10_1.x86_64.rpm \
sqlite-rpm/sqlite-3.46.1-5.el10_1.x86_64.rpm \
sqlite-rpm/sqlite-devel-3.46.1-5.el10_1.x86_64.rpm
3. 如果没有 sqlite 主包
下载对应版本:
需要:
sqlite-3.46.1-5.el10_1.x86_64.rpm
不能装:
sqlite-3.46.1-xxx
sqlite-devel-3.46.1-5.el10_1
版本必须完全匹配:
sqlite-devel
|
+-- sqlite = 3.46.1-5.el10_1
4. 如果只是为了 Python 3.13 编译
你现在的目标应该是解决:
import sqlite3
Python 编译时需要:
- sqlite-devel
- sqlite-libs
安装完成检查:
rpm -qa | grep sqlite
应该看到:
sqlite-libs-3.46.1-5.el10_1.x86_64
sqlite-3.46.1-5.el10_1.x86_64
sqlite-devel-3.46.1-5.el10_1.x86_64
5. 验证 sqlite
执行:
sqlite3 --version
例如:
3.46.1 2024-08-13 ...
6. 重新编译 Python 3.13
如果之前 Python 已经编译过:
cd Python-3.13.5
make clean
./configure \
--prefix=/usr/local/python-3.13.5 \
--enable-optimizations
make -j$(nproc)
make install
验证:
/usr/local/python-3.13.5/bin/python3.13 -c "import sqlite3; print(sqlite3.sqlite_version)"
你现在先执行:
ls -lh sqlite-rpm/
把输出贴出来,我可以告诉你缺哪个 rpm。你这个包看起来像 EL10(Alinux 3兼容 EL10)包混入了,可能还需要检查系统版本匹配
**四、**重新编译后还是报错No module named '_sqlite3'
/usr/local/python-3.13.5/bin/python3.13 -c "import sqlite3; print(sqlite3.sqlite_version)" Traceback (most recent call last): File "<string>", line 1, in <module> import sqlite3; print(sqlite3.sqlite_version) ^^^^^^^^^^^^^^ File "/usr/local/python-3.13.5/lib/python3.13/sqlite3/init.py", line 57, in <module> from sqlite3.dbapi2 import * File "/usr/local/python-3.13.5/lib/python3.13/sqlite3/dbapi2.py", line 27, in <module> from _sqlite3 import * ModuleNotFoundError: No module named '_sqlite3'
现在这个报错:
ModuleNotFoundError: No module named '_sqlite3'
说明 Python 3.13 编译时没有检测到 SQLite 开发库,所以没有编译 _sqlite3 扩展模块
虽然你现在系统里可能已经安装了 sqlite-devel,但是之前编译生成的 Python 不会自动重新链接,需要确认开发文件和重新 configure
1. 先确认 sqlite-devel 是否真的安装成功
执行:
rpm -qa | grep sqlite
应该至少有:
sqlite-3.46.1-5.el10_1.x86_64
sqlite-libs-3.46.1-5.el10_1.x86_64
sqlite-devel-3.46.1-5.el10_1.x86_64
2. 检查 sqlite 头文件
Python 编译需要:
ls -l /usr/include/sqlite3.h
正常:
-rw-r--r-- 1 root root xxxx /usr/include/sqlite3.h
如果不存在:
rpm -ql sqlite-devel | grep sqlite3.h
看它安装到了哪里
3. 清理旧 Python 编译缓存(关键)
进入 Python 源码目录:
例如:
cd /root/Python-3.13.5
执行:
make clean
或者更彻底:
make distclean
4. 重新 configure,并指定 SQLite 路径
建议:
./configure \
--prefix=/usr/local/python-3.13.5 \
--enable-optimizations \
CPPFLAGS="-I/usr/include" \
LDFLAGS="-L/usr/lib64"
重点看输出:
应该出现:
checking for sqlite3.h... yes
checking for sqlite3_libversion... yes
5. 编译安装
make -j$(nproc)
make install
6. 检查 _sqlite3.so
安装后:
find /usr/local/python-3.13.5 -name "*sqlite*"
正常应该看到:
/usr/local/python-3.13.5/lib/python3.13/lib-dynload/_sqlite3.cpython-313-x86_64-linux-gnu.so
如果没有,说明编译阶段仍然没找到 sqlite
7. 验证
/usr/local/python-3.13.5/bin/python3.13 \
-c "import sqlite3; print(sqlite3.sqlite_version)"
正常:
3.46.1
8. 如果还是没有 _sqlite3
检查 configure 日志:
grep -i sqlite config.log
重点看:
checking for sqlite3.h
checking for sqlite3_libversion
9. Alinux 3 特殊情况
你现在的包:
sqlite-devel-3.46.1-5.el10_1.x86_64
看名字是 EL10 系列包
而 Alinux 3 很可能基于:
- Alibaba Cloud Linux 3
- EL8兼容
可能导致:
- sqlite-devel 安装了
- 头文件存在
- 但是库路径/ABI不匹配
检查:
cat /etc/os-release
以及:
rpm -E %rhel
如果返回:
8
而你装的是:
el10
建议换成 Alinux 3 对应的:
sqlite-devel-3.x.x.el8.x86_64
否则 Python 编译可能无法正确链接
你现在先贴这三个输出,我可以直接判断是哪一步:
cat /etc/os-release
rpm -qa | grep sqlite
grep -i sqlite config.log | tail -20
尤其第三个,可以直接看到 Python 为什么跳过 _sqlite3
五、rpm -ql sqlite-devel | grep sqlite3.h查询为空
root@......# cat /etc/os-release NAME="Alibaba Cloud Linux" VERSION="V3" ID="alinux" ID_LIKE="anolis" VERSION_ID="3" VARIANT="Pro Edition" VARIANT_ID="pro" ALINUX_MINOR_ID="2104" ALINUX_UPDATE_ID="9" PLATFORM_ID="platform:al8" PRETTY_NAME="Alibaba Cloud Linux V3" PRETTY_NAME_ZH="阿里云服务器操作系统 V3" ANSI_COLOR="0;31" HOME_URL="https://www.aliyun.com/" BUG_REPORT_URL="https://www.aliyun.com/"
root@......# rpm -qa | grep sqlite sqlite-libs-3.26.0-19.al8.x86_64 sqlite-3.26.0-19.al8.x86_64
root@......# grep -i sqlite config.log | tail -20 grep: config.log: No such file or directory
输出已经定位原因了:
根因
你的系统:
Alibaba Cloud Linux V3
platform:al8
实际兼容 EL8
当前安装的 SQLite:
sqlite-libs-3.26.0-19.al8.x86_64
sqlite-3.26.0-19.al8.x86_64
但是:
rpm -ql sqlite-devel | grep sqlite3.h
没有输出
说明:
sqlite-devel 根本没有安装成功
你之前安装的是:
sqlite-devel-3.46.1-5.el10_1.x86_64.rpm
这是 EL10 包,不适用于 Alibaba Cloud Linux 3 (EL8兼容)
所以 Python 编译时找不到:
/usr/include/sqlite3.h
导致:
_sqlite3.cpython-313-x86_64-linux-gnu.so
没有生成
解决步骤
1. 删除错误的 EL10 sqlite 包(如果装过)
检查:
rpm -qa | grep sqlite
目前没有显示 sqlite-devel,所以不用处理
2. 安装 Alinux3 对应 sqlite-devel
你的版本应该使用:
sqlite-devel-3.26.0-19.al8.x86_64
而不是:
sqlite-devel-3.46.1-5.el10_1.x86_64
如果 yum 仓库恢复:
yum install sqlite-devel
应该安装:
sqlite-devel-3.26.0-19.al8.x86_64
3. 如果 yum 仍然无法访问阿里源,离线下载正确版本
找:
sqlite-devel-3.26.0-19.al8.x86_64.rpm
不要下载:
el10_1
安装:
rpm -ivh sqlite-devel-3.26.0-19.al8.x86_64.rpm
确认:
rpm -ql sqlite-devel | grep sqlite3.h
应该出现:
/usr/include/sqlite3.h
同时:
rpm -ql sqlite-devel | grep libsqlite
应该看到:
/usr/lib64/libsqlite3.so
4. 重新编译 Python 3.13
进入 Python 源码目录:
例如:
cd /root/Python-3.13.5
清理:
make distclean
重新配置:
./configure \
--prefix=/usr/local/python-3.13.5 \
--enable-optimizations
注意检查输出:
应该有:
checking for sqlite3.h... yes
checking for sqlite3_libversion... yes
然后:
make -j$(nproc)
make install
5. 验证
检查模块:
find /usr/local/python-3.13.5 \
-name "_sqlite3*.so"
正常:
/usr/local/python-3.13.5/lib/python3.13/lib-dynload/_sqlite3.cpython-313-x86_64-linux-gnu.so
测试:
/usr/local/python-3.13.5/bin/python3.13 \
-c "import sqlite3;print(sqlite3.sqlite_version)"
输出:
3.26.0
额外建议
Python 3.13 官方建议 SQLite >= 3.15,你当前:
sqlite 3.26.0
满足要求,可以正常使用
你现在关键动作只有一个:
yum install sqlite-devel
但因为你的 yum 源访问超时,需要先解决 repo,或者找:
sqlite-devel-3.26.0-19.al8.x86_64.rpm
不要再使用:
sqlite-devel-3.46.1-5.el10_1.x86_64.rpm
这个包属于 EL10,会导致你的 Alinux3 Python 编译环境不一致
六、make error
make error 0:02:35 load avg: 2.75 39/43 test_struct 0:02:37 load avg: 2.75 39/43 test_struct passed 0:02:37 load avg: 2.75 40/43 test_tabnanny 0:02:38 load avg: 2.75 40/43 test_tabnanny passed 0:02:38 load avg: 2.75 41/43 test_time 0:02:41 load avg: 2.53 41/43 test_time passed 0:02:41 load avg: 2.53 42/43 test_xml_etree 0:02:43 load avg: 2.53 42/43 test_xml_etree passed 0:02:43 load avg: 2.53 43/43 test_xml_etree_c 0:02:45 load avg: 2.48 43/43 test_xml_etree_c passed Total duration: 2 min 45 sec Total tests: run=9,145 failures=3 skipped=195 Total test files: run=43/43 failed=1 skipped=2 Result: FAILURE make: *** Makefile:883: profile-run-stamp Error 2
这不是普通 make 编译错误,而是因为执行了:
./configure --enable-optimizations
触发了 Python PGO(Profile Guided Optimization)编译流程
错误位置:
make: *** [Makefile:883: profile-run-stamp] Error 2
说明:
- 第一阶段 Python 已经编译成功;
- PGO 阶段运行测试失败;
- 导致整个
make失败
从日志:
Total tests: run=9,145 failures=3 skipped=195
Total test files: run=43/43 failed=1
Result: FAILURE
需要找到具体失败的 3 个测试
1. 先找到失败测试名称
在 Python 源码目录执行:
cd Python-3.13.5
查看:
grep -R "FAIL" build/*/test_python* 2>/dev/null
或者:
find . -name "*.log" | grep test
也可以重新跑:
make test
它会显示具体:
例如:
FAIL: test_xxx
2. 推荐生产服务器不要开启 PGO
你的场景:
- Alibaba Cloud Linux 3
- Python 3.13.5
- 服务运行环境
没有必要:
--enable-optimizations
这个主要用于 Python 官方 benchmark
直接关闭即可
3. 重新编译(推荐)
清理:
make distclean
重新:
./configure \
--prefix=/usr/local/python-3.13.5 \
--with-ensurepip=install
不要:
--enable-optimizations
然后:
make -j$(nproc)
make install
4. 验证 sqlite 模块
编译完成后:
/usr/local/python-3.13.5/bin/python3.13 \
-c "import sqlite3;print(sqlite3.sqlite_version)"
应该:
3.26.0
检查:
/usr/local/python-3.13.5/bin/python3.13 -m pip --version
5. 如果你坚持 PGO
需要看失败测试:
执行:
make profile-opt V=1
或者:
./python -m test -j0
找:
FAILED test_xxx
常见原因:
Alibaba Cloud Linux 3 常见:
- openssl版本
- libuuid
- timezone数据
- 容器限制
- 内核特性
- 禁止 ptrace
- CPU指令集
6. 你的情况我建议
直接:
make distclean
./configure \
--prefix=/usr/local/python-3.13.5 \
--with-lto=no \
--with-ensurepip=install
make -j$(nproc)
make install
然后:
python3.13 -c "import sqlite3"
你的核心问题是 _sqlite3,不是 Python 性能优化
另外建议确认一下:
rpm -ql sqlite-devel | grep sqlite3.h
现在应该必须看到:
/usr/include/sqlite3.h
如果这个已经有,重新编译后 _sqlite3 就会生成
七、最终解决方案
7.1 下载依赖包
sqlite-autoconf-3240000.tar.gz、sqlite-devel-3.46.1-5.el10_1.x86_64.rpm
7.2 编译安装sqlite
rpm -qa | grep sqlite
正常应该显示

-
编译安装python3.13.5
./configure
--prefix=/usr/local/python-3.13.5
--with-ensurepip=installmake -j$(nproc)
make install
验证 sqlite 模块
编译完成后:
/usr/local/python-3.13.5/bin/python3.13 \
-c "import sqlite3;print(sqlite3.sqlite_version)"
应该:
3.26.0
检查:
/usr/local/python-3.13.5/bin/python3.13 -m pip --version