3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

protobufのbuilder.pyが見つからなかった

Posted at

動作確認環境

macOS Monterey (12.2)
MacBook Air(M1、2020)
チップ: Apple M1
Python: 3.9.13
conda version: 4.14.0
protobuf: 3.19.4
mediapipe-silicon: 0.8.11

はじめに

M1macbookでmediapipeを入れて動かそうとしたところ、以下のエラー。

import mediapipe as mp
  File "~/miniforge3/envs/grad/lib/python3.9/site-packages/mediapipe/__init__.py", line 17, in <module>
    import mediapipe.python.solutions as solutions
  File "~/miniforge3/envs/grad/lib/python3.9/site-packages/mediapipe/python/solutions/__init__.py", line 17, in <module>
    import mediapipe.python.solutions.drawing_styles
  File "~/miniforge3/envs/grad/lib/python3.9/site-packages/mediapipe/python/solutions/drawing_styles.py", line 20, in <module>
    from mediapipe.python.solutions.drawing_utils import DrawingSpec
  File "~/miniforge3/envs/grad/lib/python3.9/site-packages/mediapipe/python/solutions/drawing_utils.py", line 25, in <module>
    from mediapipe.framework.formats import detection_pb2
  File "~/miniforge3/envs/grad/lib/python3.9/site-packages/mediapipe/framework/formats/detection_pb2.py", line 5, in <module>
    from google.protobuf.internal import builder as _builder
ImportError: cannot import name 'builder' from 'google.protobuf.internal' (~/miniforge3/envs/grad/lib/python3.9/site-packages/google/protobuf/internal/__init__.py)

protobuf.internal内にbuilder.pyが無いらしい。

対処

最新のバージョンのprotobufから、mediapipeが要求するバージョンのprotobufにbuilder.pyをコピーした。

  1. https://pypi.org/project/protobuf/#historyより最新のprotobufのバージョンを確認
  2. $python3 -m pip install protobuf==3.20.3
  3. $python3 -m pip show protobuf | grep Location
  4. $cp [3で出てきたパス]/google/protobuf/internal/builder.py ./builder.py
  5. $python3 -m pip install protobuf==3.19.4
  6. $python3 -m pip show protobuf | grep Location
  7. $mv ./builder.py [6で出てきたパス]/google/protobuf/internal/builder.py

(2022年10月時点では最新の4.xxがあるが、3系と4系で記述が変わってしまう可能性を考慮して3.xxでの最新にした)

おわりに

protobufはtensorboardやらtensorflow-macosの依存ライブラリとして指定されているのに、importするファイルが無いエラーが出ちゃうんだと驚いた。
こういう対処法はゴリ押し感が否めないけど動いてよかった。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?