如何解决OSX系统下TensorFlow Protobuf编译错误?
嘿,我之前在同款环境里编译TensorFlow时也踩过Protobuf的坑,给你几个亲测有效的解决方向:
严格匹配Protobuf版本:TensorFlow对Protobuf的版本依赖特别苛刻,先去你检出的TensorFlow分支根目录下找
requirements.txt,里面会明确标注需要的protobuf版本号。先卸载虚拟环境里的现有版本:pip uninstall protobuf -y再安装对应版本:
pip install protobuf==指定版本号比如我当时编译TensorFlow 1.13.x时,要求的是protobuf 3.6.1,你得对应自己的分支调整。
清理编译缓存并重新配置:残留的编译缓存很容易引发版本冲突,先彻底清理干净:
bazel clean --expunge然后重新运行配置脚本:
./configure配置过程中注意关于Protobuf路径的提问,一定要选择使用虚拟环境内的版本,别用系统自带的。
规避系统级Protobuf干扰:OSX 10.11默认自带的Protobuf版本普遍偏旧,编译时可能会优先调用系统版本。先检查当前
protoc的路径:which protoc如果输出是
/usr/bin/protoc(系统路径),就把虚拟环境的bin目录放到PATH最前面:export PATH=~/你的虚拟环境路径/bin:$PATH之后再重新执行编译命令。
确保Xcode工具链兼容:OSX 10.11.5对应的Xcode推荐用7.3.1版本,Command Line Tools也要匹配。可以通过以下命令安装对应工具:
xcode-select --install如果已经安装,在Xcode偏好设置的「Locations」里确认Command Line Tools选的是匹配版本。
拉全TensorFlow子模块:如果克隆仓库时没拉取子模块,Protobuf的源码可能缺失,执行以下命令补全所有依赖:
git submodule update --init --recursive
内容的提问来源于stack exchange,提问作者George Profenza

