anaconda版本:2021.11
python 版本: 3.7.13
安装的mediapipe版本:0.8.10
protobuf版本:4.21.1
遇到的问题:protobuf版本不对
错误提示:
>>> import mediapipe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\mediapipe\__init__.py", line 17, in <module>
import mediapipe.python.solutions as solutions
File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\mediapipe\python\solutions\__init__.py", line 17, in <module>
import mediapipe.python.solutions.drawing_styles
File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\mediapipe\python\solutions\drawing_styles.py", line 20, in <module>
from mediapipe.python.solutions.drawing_utils import DrawingSpec
File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\mediapipe\python\solutions\drawing_utils.py", line 25, in <module>
from mediapipe.framework.formats import detection_pb2
File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\mediapipe\framework\formats\detection_pb2.py", line 16, in <module>
from mediapipe.framework.formats import location_data_pb2 as mediapipe_dot_framework_dot_formats_dot_location__data__pb2
File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\mediapipe\framework\formats\location_data_pb2.py", line 16, in <module>
from mediapipe.framework.formats.annotation import rasterization_pb2 as mediapipe_dot_framework_dot_formats_dot_annotation_dot_rasterization__pb2
File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\mediapipe\framework\formats\annotation\rasterization_pb2.py", line 42, in <module>
options=None),
File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\google\protobuf\descriptor.py", line 560, 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
解决办法:
pip uninstall protobuf
pip install protobuf==3.20
解决后: