MacOS Ventura+Python3.12安装aiogram3时aiohttp编译失败求助
解决MacOS Ventura + Python 3.12下安装aiogram3时aiohttp/multidict编译失败的问题
问题根源
Python 3.12对C扩展API做了破坏性变更,比如移除了struct _longobject的ob_digit成员,同时调整了部分指针类型定义。旧版本的aiohttp、multidict未适配这些变更,导致本地编译时出现报错。
解决方案
升级pip并安装适配版本的依赖
首先确保pip是最新版,避免版本兼容问题:pip install --upgrade pip目前aiohttp >= 3.9.0、multidict >= 6.0.4已经完全适配Python 3.12,aiogram >= 3.3.0也已同步支持。直接安装即可:
pip install "aiogram>=3.3.0"或者单独指定依赖版本后再安装aiogram:
pip install "aiohttp>=3.9.0" "multidict>=6.0.4" aiogram==3.4.1强制使用预编译二进制包
如果本地编译环境(比如LLVM、Xcode工具链)仍存在问题,让pip优先下载预编译的轮子(无需本地编译):pip install aiogram --only-binary :all:也可以单独为依赖包启用该选项:
pip install aiohttp multidict --only-binary :all:修复Xcode命令行工具环境
确保MacOS的编译工具链完整且最新:- 安装/更新Xcode命令行工具:
xcode-select --install - 若已安装,重置工具链路径:
sudo xcode-select --reset - 同意Xcode许可证(避免编译权限问题):
sudo xcodebuild -license accept
- 安装/更新Xcode命令行工具:
确认Python环境正确性
避免混用系统Python或其他版本的Python环境:- 检查当前Python路径,确保是你安装的3.12版本(比如Homebrew安装的路径通常是
/opt/homebrew/bin/python3):which python3 - 使用虚拟环境隔离依赖:
# 创建虚拟环境 python3 -m venv aiogram-env # 激活环境 source aiogram-env/bin/activate # 安装aiogram pip install aiogram
- 检查当前Python路径,确保是你安装的3.12版本(比如Homebrew安装的路径通常是
内容的提问来源于stack exchange,提问作者EgorGorshan
相关产品推荐
相关产品推荐

