LoginSignup
1
2

More than 1 year has passed since last update.

M1MAX MacBook Pro にTensorFlowをインストールする方法

Posted at

機械学習講座を受けるためにM1MAX搭載のMacBook Pro(2021)にTensorFlowをインストールします。

んー、なんでPytorchじゃないのか(愚痴)

環境は、
M1MAX macbookpro 2021
Pythonは
/opt/homebrew/opt/python@3.9/libexec/bin/python
HomeBrewのPython3.9です

まず普通にpip installしてみます。

python -m pip install tensorflow-macos

Successfully installed astunparse-1.6.3 gast-0.4.0 google-pasta-0.2.0 h5py-3.7.0 keras-2.10.0 keras-preprocessing-1.1.2 libclang-14.0.6 opt-einsum-3.3.0 tensorflow-estimator-2.10.0 tensorflow-macos-2.10.0 termcolor-2.0.1 wrapt-1.14.1

なんか途中に色々とワーニングがでましたが、インストールができたっぽい。
動作確認します。

python
Python 3.9.15 (main, Oct 11 2022, 21:39:54) 
[Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
ImportError: numpy.core._multiarray_umath failed to import
ImportError: numpy.core.umath failed to import
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.9/site-packages/tensorflow/__init__.py", line 37, in <module>
・・・・・・・・(略)

pip list にはTensorFlowがいるのに動かないですね。。。困った。

HomeBrewでインストールしたPythonではだめだという情報もありました。
参考(からあげさん)
M1 Macでディープラーニングしてみる

githubのtensorflow_macosを見てみます。

2022/10/15時点では最新は、「Version 0.1-alpha3」のようですね。
さらにPython 3.8のみに対応。

だめじゃん。。。。うち3.9だし。Anaconda使いたくないし( ・`ω・´)キリッ

んーーー、
ん?

File "/opt/homebrew/lib/python3.9/site-packages/tensorflow/python/framework/dtypes.py", line 34, in <module>
    _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
TypeError: Unable to convert function return value to a Python type! The signature was
	() -> handle

先ほどのエラーを見直すと、float関係でエラーが出てますね。。(適当)
numpyをアップグレードしてみましょう(適当)

pip install numpy --upgrade

さてもう一度TensorFlowの動作確認を行います。

python
Python 3.9.15 (main, Oct 11 2022, 21:39:54) 
[Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.10.0'
>>> 

やったぜい!!!!

1
2
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
1
2