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

解决Google API与Gspread的Python包依赖冲突问题

解决gspread与Google Analytics API的依赖冲突问题

核心原因

你遇到的冲突根源在于:

  • gspread 5.7.0强制要求google-auth==1.12.0
  • Google Analytics Reporting API v4依赖的google-api-python-client 2.50.0和google-api-core 2.8.1需要更高版本的google-auth(通常要求>=2.1.0)

最佳解决方法(推荐)

升级gspread到最新稳定版,新版本已移除对google-auth的严格版本限制,可兼容更高版本的google-auth,同时满足GA API的需求:

  1. 卸载现有gspread:
pip uninstall -y gspread
  1. 安装最新版gspread:
pip install gspread --upgrade
  1. 升级GA API相关依赖包到兼容版本:
pip install --upgrade google-auth google-api-python-client google-api-core

执行完以上步骤后,两个工具的依赖即可兼容,既能正常调用GA API,也能使用gspread操作Google Sheets。

备选方案(若需保留gspread 5.7.0)

如果必须使用gspread 5.7.0,可降级GA API相关依赖包到兼容google-auth 1.12.0的版本:

  1. 卸载现有冲突的GA API依赖:
pip uninstall -y google-api-python-client google-api-core
  1. 安装兼容旧版google-auth的指定版本:
pip install google-api-python-client==2.30.0 google-api-core==2.2.2
  1. 确保gspread版本为5.7.0:
pip install gspread==5.7.0

新手友好建议

无论采用哪种方案,都建议使用Python虚拟环境隔离项目依赖,避免全局包冲突:

  • 在Jupyter Notebook中,可通过conda或venv创建虚拟环境,激活环境后再安装所需包。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 14:10:28