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

Ubuntu环境下Protobuf版本不匹配问题求助

解决TensorFlow 2.3.0在Ubuntu 20.04下的Protobuf版本冲突问题

问题场景

基于TensorFlow的Python应用在Windows 10运行正常,迁移至Ubuntu 20.04.4系统、通过pip install tensorflow==2.3.0安装同版本TensorFlow后,出现以下报错:

[libprotobuf FATAL google/protobuf/stubs/common.cc:83] This program was compiled against version 3.9.2 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.19.4). Contact the program author for an update. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "bazel-out/k8-opt/bin/tensorflow/core/framework/tensor_shape.pb.cc".)
Aborted (core dumped)

当前环境检查结果:

  • pip安装的protobuf版本为3.19.4:
pip show protobuf
# 输出:
Name: protobuf
Version: 3.19.4
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author:
Author-email:
License: BSD-3-Clause
Location: /home/username/anaconda3/envs/my_env/lib/python3.8/site-packages
Requires:
Required-by: tensorboard, tensorflow
  • 系统未安装protoc工具:
protoc --version
# 输出:
Command 'protoc' not found, but can be installed with:

snap install protobuf           # version 3.14.0, or
apt  install protobuf-compiler  # version 3.6.1.3-2ubuntu5

See 'snap info protobuf' for additional versions.

解决步骤

1. 降级Protobuf到TensorFlow 2.3.0依赖版本

TensorFlow 2.3.0编译时依赖的Protobuf版本为3.9.2,直接降级pip中的Protobuf:

pip install protobuf==3.9.2

执行完成后用pip show protobuf确认版本已切换为3.9.2。

2. 排查系统层面的Protobuf库冲突

Ubuntu系统可能存在预装的Protobuf系统库,即使未安装protoc,也可能与虚拟环境中的库冲突:

ldconfig -p | grep protobuf

若输出非3.9.2版本的库,可通过临时设置环境变量指定TensorFlow使用虚拟环境内的库:

export LD_LIBRARY_PATH=/home/username/anaconda3/envs/my_env/lib/python3.8/site-packages/google/protobuf/pyext/:$LD_LIBRARY_PATH

设置完成后再运行Python应用。

3. 创建干净的虚拟环境(彻底解决依赖缓存问题)

如果上述方法无效,重新创建conda环境可清除潜在的依赖冲突:

conda deactivate
conda remove -n my_env --all
conda create -n my_env python=3.8
conda activate my_env
# 先安装指定版本Protobuf,再安装TensorFlow
pip install protobuf==3.9.2
pip install tensorflow==2.3.0

4. 重新安装并清理缓存

若TensorFlow安装不完整,执行以下操作重装:

pip uninstall tensorflow protobuf -y
pip cache purge
pip install protobuf==3.9.2 tensorflow==2.3.0

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 11:23:17