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

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的编译工具链完整且最新:

    1. 安装/更新Xcode命令行工具:
      xcode-select --install
      
    2. 若已安装,重置工具链路径:
      sudo xcode-select --reset
      
    3. 同意Xcode许可证(避免编译权限问题):
      sudo xcodebuild -license accept
      
  • 确认Python环境正确性
    避免混用系统Python或其他版本的Python环境:

    1. 检查当前Python路径,确保是你安装的3.12版本(比如Homebrew安装的路径通常是/opt/homebrew/bin/python3):
      which python3
      
    2. 使用虚拟环境隔离依赖:
      # 创建虚拟环境
      python3 -m venv aiogram-env
      # 激活环境
      source aiogram-env/bin/activate
      # 安装aiogram
      pip install aiogram
      

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 16:01:18