python-3.x Ubuntu上的Protobuf版本不匹配

xxhby3vn  于 2023-04-08  发布在  Python
关注(0)|答案(1)|浏览(198)

我有一个基于TensforFlow的Python应用程序,在装有Windows 10的PC上运行良好。但是,当我将应用程序传输到另一台装有Ubuntu 20.04.4的PC上时,使用相同的环境,我会收到以下错误:

[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)

我不知道老版本的protobuf(3.9.2)是从哪里来的。

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

我没有安装任何其他版本的protocol buffers:

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.

在这两台机器上,TensorFlow都是通过pip安装的,没有任何本地构建/编译。

pip install tensorflow==2.3.0

有什么建议吗?

42fyovps

42fyovps1#

我发现这个问题是由Python文件中导入的顺序引起的。我必须将所有与TensorFlow相关的导入放在第一位:

# Original order of imports that caused the error on Ubuntu

import detectron2
import EasyOCR
import Tensorflow

# Modified order of imports that works fine on Ubuntu

import Tensorflow # in first place!  
import detectron2
import EasyOCR

我还必须重新排列所有上层导入,以便将我的模块与Tensorflow导入放在首位:

# Original order of imports that caused the error on Ubuntu

import local module without Tensorflow imports 1
import local module without Tensorflow imports 2
import local module without Tensorflow imports 3
import local module with Tensorflow imports inside

# Modified order of imports that works fine on Ubuntu

import local module with Tensorflow imports inside # in first place!    
import local module without Tensorflow imports 1
import local module without Tensorflow imports 2
import local module without Tensorflow imports 3

相关问题