导入mediapipe出现TypeError: Descriptors cannot not be created directly.的解决方法

一、错误:

树莓派使用mediapipe时出现的错误,

 import mediapipe

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/home/pi/.local/lib/python3.7/site-packages/mediapipe/__init__.py", line 17, in <module>

    import mediapipe.python.solutions as solutions

  File "/home/pi/.local/lib/python3.7/site-packages/mediapipe/python/solutions/__init__.py", line 17, in <module>

    import mediapipe.python.solutions.drawing_styles

  File "/home/pi/.local/lib/python3.7/site-packages/mediapipe/python/solutions/drawing_styles.py", line 20, in <module>

    from mediapipe.python.solutions.drawing_utils import DrawingSpec

  File "/home/pi/.local/lib/python3.7/site-packages/mediapipe/python/solutions/drawing_utils.py", line 25, in <module>

    from mediapipe.framework.formats import detection_pb2

  File "/home/pi/.local/lib/python3.7/site-packages/mediapipe/framework/formats/detection_pb2.py", line 15, in <module>

    from mediapipe.framework.formats import location_data_pb2 as mediapipe_dot_framework_dot_formats_dot_location__data__pb2

  File "/home/pi/.local/lib/python3.7/site-packages/mediapipe/framework/formats/location_data_pb2.py", line 15, in <module>

    from mediapipe.framework.formats.annotation import rasterization_pb2 as mediapipe_dot_framework_dot_formats_dot_annotation_dot_rasterization__pb2

  File "/home/pi/.local/lib/python3.7/site-packages/mediapipe/framework/formats/annotation/rasterization_pb2.py", line 41, in <module>

    serialized_options=None, file=DESCRIPTOR),

  File "/home/pi/.local/lib/python3.7/site-packages/google/protobuf/descriptor.py", line 561, in __new__

    _message.Message._CheckCalledFromGeneratedFile()

TypeError: Descriptors cannot not be created directly.

If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.

If you cannot immediately regenerate your protos, some other possible workarounds are:

 1. Downgrade the protobuf package to 3.20.x or lower.

 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).



More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

根据报错信息,是我们的protobuf版本过高,需要降低到3.20.x版本或以下

根据网络上查找的解决方法,都是让安装 protobuf3.20 版本,安装这个版本确实有用,但是通过正常的 pip3 install protobuf==3.20 是无法安装的,会报错:

No matching distribution found for protobuf==3.20

意思是没有找到对应版本的protobuf

二、解决方法:

从我资源里下载 protobuf3.20.1,传到板子上去,然后执行安装命令:

pip3 install protobuf-3.20.1-py2.py3-none-any.whl

资源链接:protobuf-3.20.1-py2.py3-none-any.whl

执行结果并测试:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值