1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Build env for Tensor-flow and ML on Mac(Apple Silicon)

Last updated at Posted at 2024-08-31

agenda

  • homebrew
  • pyenv
  • metal as GPU driver
  • tensor-flow

homebrew

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

pyenv

brew install xz
brew install pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc

source ~/.zshrc

pyenv install --list
pyenv install 3.12.9
pyenv global 3.12.9

miniforge

install
brew install miniforge

conda init

conda init

.bash_profileに追記された"conda initialize"というコメントを現在のログインシェルに転記する

.zshrc
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/homebrew/Caskroom/miniforge/base/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
        . "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh"
    else
        export PATH="/opt/homebrew/Caskroom/miniforge/base/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<
exec -l $SHELl

再ログインし、プロンプトに"(base)"と付けばOK

conda create env

condaの環境設定について、スクラップ&ビルドをしやすくするために名前をつけておく

conda env list

この時点では、baseのみの想定

conda create -n py312 python=3.12
conda activate py312

※activateに失敗する場合はターミナルの確実な再起動(Dock上のアイコンにて終了を選択する)または、PCの再起動をする

なお、作った環境以外を使いたい場合などはdeactivateする

conda deactivate

tensorflow

python -m pip install tensorflow-macos
python -m pip install tensorflow-metal

check

python

import tensorflow as tf
print(tf.__version__)

exit()

transformer

conda install -c huggingface transformers

ML

conda install -c conda-forge scikit-learn
conda install -c conda-forge pandas
conda install -c conda-forge jupyterlab notebook
conda install -c pytorch torchvision
conda install -c conda-forge matplotlib
conda install -c conda-forge polars
conda install -c conda-forge metpy
conda install -c scitools cartopy
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?