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

升级至Gemini 2.5时Google Generative AI与LangChain版本冲突问题

依赖冲突解决:升级Gemini 2.5兼容Langchain

问题背景

要从Gemini 1.5切换到Gemini 2.5 Experimental,需升级google-ai-generativelanguage和google-generativeai版本以支持新模型,但通过requirements.txt管理依赖时,这两个包的新版本与当前使用的Langchain 0.2.6系列版本存在冲突。此前尝试使用google-ai-generativelanguage==0.6.15和google-generativeai==0.8.4,但无法与现有Langchain兼容。

当前requirements.txt内容:

Flask==3.0.3
Flask-Cors==4.0.1
frozenlist==1.4.1
google-ai-generativelanguage==0.6.5
google-api-core==2.19.0
google-api-python-client==2.131.0
google-auth==2.29.0
google-auth-httplib2==0.2.0
google-cloud-core==2.4.1
google-cloud-firestore==2.16.0
google-cloud-storage==2.16.0
google-crc32c==1.5.0
google-generativeai==0.7.0
google-resumable-media==2.7.0
googleapis-common-protos==1.63.1
grpcio==1.64.0
grpcio-status==1.62.2
gunicorn==22.0.0
h11==0.14.0
httpcore==1.0.5
httplib2==0.22.0
httpx==0.27.0
idna==3.7
importlib_metadata==7.1.0
itsdangerous==2.2.0
Jinja2==3.1.4
jmespath==1.0.1
jsonpatch==1.33
jsonpointer==3.0.0
langchain==0.2.6
langchain-community==0.2.6
langchain-core==0.2.10
langchain-google-genai==1.0.7
langchain-text-splitters==0.2.2
langsmith==0.1.82
MarkupSafe==2.1.5
marshmallow==3.21.3
msgpack==1.0.8
multidict==6.0.5
stripe==6.0.0
mypy-extensions==1.0.0
numpy==1.26.4
openai==0.28.0
orjson==3.10.5
packaging==24.1
pathspec==0.10.1
pipenv==2023.12.1
platformdirs==4.2.2
proto-plus==1.23.0
protobuf==4.25.3
pyasn1==0.6.0
pyasn1_modules==0.4.0
pycparser==2.22
pydantic==2.7.3
pydantic_core==2.18.4
PyJWT==2.8.0
pyparsing==3.1.2
PyPDF2==3.0.1
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
PyYAML==6.0.1
requests==2.32.3
rsa==4.9
semantic-version==2.8.5
six==1.16.0
sniffio==1.3.1
SQLAlchemy==2.0.31
tenacity==8.4.2
termcolor==1.1.0
tqdm==4.66.4
typing-inspect==0.9.0
typing_extensions==4.12.1
uritemplate==4.1.1
urllib3==1.26.18
virtualenv==20.26.2
wcwidth==0.1.9
Werkzeug==3.0.3
yarl==1.9.4
zipp==3.19.1
joblib==1.3.2

解决方案

方案1:升级Langchain到兼容版本

Langchain 0.2.x早期版本对google-generativeai的版本限制严格,google-generativeai>=0.8.0需要更高版本的Langchain支持。将Langchain相关包更新为以下兼容版本:

  • langchain==0.2.10
  • langchain-community==0.2.10
  • langchain-core==0.2.22
  • langchain-google-genai==1.0.10
  • langchain-text-splitters==0.2.2
  • langsmith==0.1.90

同时更新Google相关包:

  • google-ai-generativelanguage==0.6.15
  • google-generativeai==0.8.4

方案2:放宽版本限制(临时解决)

若不想升级Langchain,可暂时移除Google相关包的硬版本限制,让pip自动匹配兼容版本:

google-ai-generativelanguage>=0.6.15
google-generativeai>=0.8.4

执行安装时添加--upgrade参数:

pip install -r requirements.txt --upgrade

注意:此方式可能引发其他依赖的不可预见问题,需在测试环境验证后再部署到生产。

方案3:用虚拟环境隔离依赖

创建新虚拟环境,先安装兼容的Google包和Langchain版本,再逐步迁移其他依赖:

# 创建虚拟环境
python -m venv gemini2.5-env
# Windows激活虚拟环境
gemini2.5-env\Scripts\activate
# Linux/Mac激活虚拟环境
source gemini2.5-env/bin/activate
# 先安装核心兼容包
pip install langchain==0.2.10 langchain-google-genai==1.0.10 google-generativeai==0.8.4 google-ai-generativelanguage==0.6.15
# 再安装其他依赖
pip install Flask==3.0.3 Flask-Cors==4.0.1 ...(其余依赖项)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 14:39:55