[MediaPipe Python] 解決 Import 時發生的 TypeError: Descriptors cannot not be created directly

發表日期:
2022.06.24
/
分類:
Dev
目前最新版本 MediaPipe Python 套件會發生相依套件的版本問題,需對 protobuf 進行降版處理。 錯誤訊息 直接用 pip 指令安裝最新版本 MediaPipe 後進行 import 時會發生以下錯誤: TypeError: Descriptors cannot not be created directly.

目前最新版本 MediaPipe Python 套件會發生相依套件的版本問題,需對 protobuf 進行降版處理。

錯誤訊息

直接用 pip 指令安裝最新版本 MediaPipe 後進行 import 時會發生以下錯誤:

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.* 版本即可解決:

pip uninstall protobuf
pip install protobuf==3.20.*

參考資料

python - TypeError: Descriptors cannot not be created directly - Stack Overflow

comments powered by Disqus