【未解決】 pip3 install -q tflite-model-makerしたい (M1 Mac)

環境:
MacOS Ventura
Python 3.10.9

9:50 Start!

このチュートリアルに従う

GitHub リポジトリ にある Model Maker パッケージなど、いくつかの必要なパッケージをインストールしてください。

リポジトリを見てみる
https://github.com/tensorflow/examples/tree/master/tensorflow_examples/lite/model_maker

Requirements
Refer to requirements.txt for dependent libraries that're needed to use the library and run the demo code.

demoを試してみろと書いてあるので、リポジトリをクローンしてみた。

Terminalで、クローンしたリポジトリに移動して、
% cd tensorflow_examples
% cd lite
% cd model_maker
% python3 __init__.py

エラーは出なかった。 しかしログも何も出ない。できたのか?
できたことにして先に進む。

% pip3 install tflite-model-maker

Error
raise AttributeError(attr)
AttributeError: cython_sources

% pip3 install "Cython<3.0" pyyaml --no-build-isolation
→ 意味ない

% pip3 install numpy==1.23.4
-> 意味ない

10:30

Python 3.9にダウングレードしてみる
% brew uninstall --ignore-dependencies python@3.10
% brew install python@3.9

% brew switch python 3.9.0
Error: Unknown command: switch
どうやらswitchはdeprecatedらしい。

% python3 --version
Python 3.11.5
なんでかバージョンあがっとる。。?

% pip3 install tflite-model-maker
同じエラー

% brew install pyenv
% pyenv install 3.9.0
Error: make: *** No targets specified and no makefile found.  Stop.

一個もうまくいかないよーーーー

./configureすればいいらしい
% ./configure
Error: zsh: no such file or directory: ./configure

🙂

pyenvは前から入ってたからいらないと思ったけど、ここらへんもやってみる
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

% pyenv install 3.9.0
Error: make: *** No targets specified and no makefile found.  Stop.
どうして。。

上のエラーの前にこんなのもあった。
configure: error: Unexpected output of 'arch' on OSX

pyenvがM1に対応してないらしい
% arch -arch x86_64 pyenv install 3.8.7

3分くらい待って。。
Error:
… died with <Signals.SIGABRT: 6>.
make: *** [install] Error 1

homebrewをインストールし直す

$ brew cleanup
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

pyenvをインストールしなおし
% brew install pyenv
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

% arch -arch x86_64 pyenv install 3.8.7

11:30

tukaretayo---

できたーーー!!!
Successfully installed pip-20.2.3 setuptools-49.2.1
ここからが本題。

% python3 --version
Python 3.9.6
全然関係ないバージョンが設定されてるぞ。
でも問題のある3.10じゃないからいけるかも?

% pip3 install tflite-model-maker
AttributeError: cython_sources
 [end of output]

ぁあああああ

「もしconda使ってるならこうやりなよ!」って言ってるけどcondaってなに?

壮大なインストールが必要そう。インストールはしないとして。

何かすごい基本的なことができていないんだろう。
しかし何を理解できていないのかわからないから調べられない。

ログで上の方に表示されてたやつも調べてみた。
Getting requirements to build wheel ... error

$ echo "Cython<3" > cython_constraint.txt
$ PIP_CONSTRAINT=cython_constraint.txt pip3 install "ai-core-sdk[aicore-content]"

% pip3 install tflite-model-maker       

10分ほど待った

ERROR: Cannot install tflite-model-maker==0.1.2, tflite-model-maker==0.2.0, tflite-model-maker==0.2.1, tflite-model-maker==0.2.2, tflite-model-maker==0.2.3, tflite-model-maker==0.2.4, tflite-model-maker==0.2.5, tflite-model-maker==0.3.0, tflite-model-maker==0.3.1, tflite-model-maker==0.3.2, tflite-model-maker==0.3.3, tflite-model-maker==0.3.4, tflite-model-maker==0.4.0, tflite-model-maker==0.4.1 and tflite-model-maker==0.4.2 because these package versions have conflicting dependencies.

いろんなバージョンのtflite-model-makerをインストールしようとしてエラーになってる?全バージョンはいらないと思うんだけど。。

まあほとんどはインストールできてるし良しとしよう。

やっとこのガイドに戻る。

必要なパッケージをインポートします。

とあるけど、どこで?勝手になんかのテキストファイル作ってることになってるんだが。
とりあえずmain.pyを作って以下ををコピペ。

import os

import numpy as np

import tensorflow as tf
assert tf.__version__.startswith('2')

from tflite_model_maker import model_spec
from tflite_model_maker import image_classifier
from tflite_model_maker.config import ExportFormat
from tflite_model_maker.config import QuantizationConfig
from tflite_model_maker.image_classifier import DataLoader

import matplotlib.pyplot as plt

まずこの段階で問題ないかテスト

% python3 main.py
… /main.py", line 5, in <module>
    import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

tensorflow/examples/tensorflow_examples/liteのrequirements.txtをコピペ

% pip3 install -r requirements.txt
ERROR: Could not find a version that satisfies the requirement tflite-support>=0.4.2 (from versions: 0.1.0a0.dev3, 0.1.0a0.dev4, 0.1.0a0.dev5, 0.1.0a0, 0.1.0a1)
ERROR: No matching distribution found for tflite-support>=0.4.2

おいい。。

https://github.com/tensorflow/tflite-support/issues/858

% python3 -m pip install pip --upgrade
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in /Users/username/Library/Python/3.9/lib/python/site-packages (23.2.1)

 関係ないっぽい

コメントアウトして
#tflite -support>=0.4.2
再トライ
% pip3 install -r requirements.txt
ERROR: Ignored the following versions that require a different python version: 0.52.0 Requires-Python >=3.6,<3.9; 0.52.0rc3 Requires-Python >=3.6,<3.9
ERROR: Could not find a version that satisfies the requirement scann==1.2.6 (from versions: none)
ERROR: No matching distribution found for scann==1.2.6

またpythonダウングレードが必要みたい

$ arch -arch x86_64 pyenv install 3.8.7

こっそりこんなエラーが出てた
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

https://qiita.com/pokotsun/items/3ebab483b0e134ab1726

$ CFLAGS=-I/usr/include/openssl LDFLAGS=-L/usr/lib pyenv install -v

$ arch -arch x86_64 pyenv install 3.8.7
同じエラー

https://github.com/pyenv/pyenv/wiki#suggested-build-environment

$ xcode-select --install                  
xcode-select: error: command line tools are already installed, use "Software Update" in System Settings to install updates
$ brew install openssl readline sqlite3 xz zlib tcl-tk
$ arch -arch x86_64 pyenv install 3.8.7
同じエラー

OpenSSLをインストールする

12:40

OpenSSLインストールの最後のステップで
% su
su: Sorry
ってなったけどなんだろう。

$ arch -arch x86_64 pyenv install 3.8.7
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

OpenSSLインストールできてないっぽい?

% openssl version
OpenSSL 3.1.2 1 Aug 2023 (Library: OpenSSL 3.1.2 1 Aug 2023)

あるな。。

su: Sorryについて調べる

ルートユーザーのパスワードとやらを変更した
% su
sh-3.2#
sh-3.2#
sh-3.2#

escクリックしても抜け出せない。
この中で試しに

sh-3.2# arch -arch x86_64 pyenv install 3.8.7
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

まあ無理か

% CFLAGS=-I/usr/include/openssl LDFLAGS=-L/usr/lib pyenv install -v 3.8.7
Error: make: *** No targets specified and no makefile found.  Stop.

さっきダウンロードしたopenssl-3.1.2フォルダに移動して

% CFLAGS=-I/usr/include/openssl LDFLAGS=-L/usr/lib pyenv install -v 3.8.7
Error: make: *** No targets specified and no makefile found.  Stop.

https://qiita.com/ukwksk/items/2fd46812bc66ed06e9b0

% brew doctor
% brew cleanup
% CFLAGS=-I/usr/include/openssl LDFLAGS=-L/usr/lib pyenv install -v 3.8.7
Error: make: *** No targets specified and no makefile found.  Stop.

古いツールの削除
$ sudo rm -rf /Library/Developer/CommandLineTools
新しいCommandLineToolsのインストール
$ xcode-select --install
$ pyenv install 3.9.7

$ pyenv versions
  system
* 2.7.18 (set by /Users/username/.pyenv/version)
  3.9.7

できた!!!!!!
でもインストールしたかったのは3.8.7だ。
% pyenv install 3.8.7
make: *** No targets specified and no makefile found.  Stop.

🙂…………….

13:34

$ arch -arch x86_64 pyenv install 3.8.7
毎回結構時間がかかる
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

どの記事見てもこれでできたって言ってる

ダメおし
% pip3 install tflite-model-maker
ERROR: Cannot install tflite-model-maker==0.1.2, tflite-model-maker==0.2.0, tflite-model-maker==0.2.1,…

https://github.com/tensorflow/tensorflow/issues/60493

Sorry for the inconvenience caused. The mediapipe model maker is yet to support on arm mac devices. As a workaround please use colab for using the mediapipe model maker.

nandato….

13:50

firebaseでTensorFlow liteを使いたいんだけど、mediapipeでもいけるのか?

flutterで使えるが、iOSで使えない。。😭


この記事が気に入ったらサポートをしてみませんか?