Mac下适配Python protobuf 3.19.X的protoc版本降级方案
适配Python protobuf 3.19.6的protoc降级方案
需要降级到的protoc版本
必须将protoc降级到3.19.6版本,protoc版本需要与Python环境中protobuf runtime版本严格匹配,否则会出现生成代码与runtime不兼容的问题(比如你遇到的builder导入错误)。
Homebrew操作步骤(Mac/Linux通用)
- 卸载当前安装的高版本protobuf
brew uninstall protobuf - 安装指定的3.19.x版本protobuf(Homebrew提供的
protobuf@3.19包默认对应3.19.6)brew install protobuf@3.19 - 强制链接该版本,覆盖系统中可能存在的其他protoc版本
brew link protobuf@3.19 --force --overwrite - 验证版本是否正确
终端应返回protoc --versionlibprotoc 3.19.6
如果protobuf@3.19包的版本不是3.19.6,可以通过以下方式安装精确版本:
- 先查看protobuf的历史提交记录,找到3.19.6对应的commit哈希
brew log protobuf - 直接从对应commit的Formula文件安装
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<替换为3.19.6的commit哈希>/Formula/protobuf.rb - 安装完成后重复步骤3和4验证版本
内容的提问来源于stack exchange,提问作者Jed
相关产品推荐
相关产品推荐

