Tensorflow protobuf版本报错问题解决(AttributeError: 'module' object has no attribute 'Default')

本文记录了解决TensorFlow因protobuf版本不匹配导致无法正常运行的问题。通过排查发现protobuf存在多个版本,最终找到对应TensorFlow版本所需的protobuf版本并替换安装,成功解决了问题。
无意中发现TF跑不了,报的错误是:
AttributeError: 'module' object has no attribute 'Default'
如下:
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 75, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/home/schidester/usr/tf/local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 9, in <module>
    from google.protobuf import symbol_database as _symbol_database
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/symbol_database.py", line 165, in <module>
    _DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
AttributeError: 'module' object has no attribute 'Default'

关于这个问题,网上有各种解决方案,但是始终不对。
pip install --upgrade protobuf等这种办法,发现这样操作之后仍旧是无效。
后来进到/usr/loca/lib/python3.6/site-packages/中才发现,里面的protobuf版本有3.2,3.4等多个版本。
没有办法,只好去看https://github.com/tensorflow/tensorflow/releases中关于protobuf的相关说明,才发现里面需要用到的tf对应的protobuf版本是3.0.0b2,
https://pypi.python.org/pypi/protobuf/3.0.0b2,从这个网站上进行下载WHL文件,再进行安装,果然顺利成功。解决该问题。

2025-11-16 13:45:28.591323: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered WARNING: All log messages before absl::InitializeLog() is called are written to STDERR E0000 00:00:1763300728.613357 314 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered E0000 00:00:1763300728.620145 314 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered AttributeError: 'MessageFactory' object has no attribute 'GetPrototype' AttributeError: 'MessageFactory' object has no attribute 'GetPrototype' AttributeError: 'MessageFactory' object has no attribute 'GetPrototype' AttributeError: 'MessageFactory' object has no attribute 'GetPrototype' AttributeError: 'MessageFactory' object has no attribute 'GetPrototype' Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/ray/train/__init__.py", line 32, in <module> import pydantic # noqa: F401 ^^^^^^^^^^^^^^^ ModuleNotFoundError: No module named 'pydantic' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/kaggle/working/llama-factory/LLaMA-Factory-main/src/train.py", line 1, in <module> from llamafactory.train.tuner import run_exp File "/kaggle/working/llama-factory/LLaMA-Factory-main/src/llamafactory/train/tuner.py", line 31, in <module> from .dpo import run_dpo File "/kaggle/working/llama-factory/LLaMA-Factory-main/src/llamafactory/train/dpo/__init__.py", line 15, in <module> from .workflow import run_dpo File "/kaggle/working/llama-factory/LLaMA-Factory-main/src/llamafactory/train/dpo/workflow.py", line 26, in <module> from ..trainer_utils import create_modelcard_and_push, create_ref_model File "/kaggle/working/llama-factory/LLaMA-Factory-main/src/llamafactory/train/trainer_utils.py", line 52, in <module> from ray.train import RunConfig, ScalingConfig File "/usr/local/lib/python3.11/dist-packages/ray/train/__init__.py", line 34, in <module> raise ImportError( ImportError: `ray.train.v2` requires the pydantic package, which is missing. Run the following command to fix this: `pip install pydantic`
最新发布
11-17
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值