如何解决Google App Engine中google-cloud存储与日志依赖冲突?
当requirements.txt仅包含以下依赖时:
google-cloud-storage google-cloud-logging
会触发依赖冲突警告:
WARNING: Found incompatible dependencies: "google-cloud-datastore 1.15.5 has requirement protobuf<4.0.0dev, but you have protobuf 4.21.7
尝试指定protobuf==3.20.1时,又会出现新的冲突:
WARNING: Found incompatible dependencies: "google-cloud-logging 3.2.5 has requirement protobuf!=3.20.0,!=3.20.1,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.1.
google-cloud-appengine-logging 1.1.6 has requirement protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.1.
google-api-core 2.10.2 has requirement protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.1.
可行解决方案
锁定兼容的版本组合
选择同时满足两个库依赖要求的版本,比如使用以下requirements.txt:google-cloud-storage==2.10.0 google-cloud-logging==3.7.0 protobuf==3.19.6这个组合中,
protobuf 3.19.6既符合google-cloud-datastore对<4.0.0dev的要求,又避开了google-cloud-logging等组件排除的3.20.0/1版本,同时两个核心库的版本也能正常兼容这个protobuf版本。使用约束文件强制版本
如果不想修改原有的依赖声明,可以创建constraints.txt文件,内容如下:protobuf==3.19.6安装依赖时执行命令:
pip install -r requirements.txt -c constraints.txt该命令会强制pip使用指定的protobuf版本,同时自动调整其他依赖的兼容版本。
等待官方修复
可以留意Google Cloud官方后续发布的SDK版本,看是否已统一依赖版本要求,解决这类跨库的兼容性冲突。
内容的提问来源于stack exchange,提问作者Joshua Smith

