Macbook air m2 개발환경 설정하기

cloud2000·2023년 11월 12일

Python 가상 환경

1.anaconda 설치

jupyter notebook을 설치하여 Apple M2 GPU를 사용하는 환경을 마련해 보자

  • 현재 시점(23.11.11)에 homebrew로 설치는 문제없이 된다.
brew install --cask anaconda
export PATH="/opt/homebrew/anaconda3/bin:$PATH"
  • zshrc에 anaconda 설치 경로를 PATH에 추가한다.
$ vi ~/.zshrc 
export PATH=$HOME/bin:/usr/local/bin:$PATH:/opt/homebrew/anaconda3/bin
. ~/.zshrc

# 아나콘다 설정 초기화
$ which conda
/opt/homebrew/anaconda3/bin

$ conda init zsh
  • terminal을 종료하고 다시 기동하면 prompt가 아래와 같이 변경되면서 가상환경임으로 알수 있다.
(base) ➜  ~ python --version
Python 3.11.5

2.가상 환경을 추가한다

(base) ➜  ~ conda create -n lab1
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 23.7.4
  latest version: 23.10.0

Please update conda by running

    $ conda update -n base -c defaults conda

Or to minimize the number of packages updated during conda update use

     conda install conda=23.10.0



## Package Plan ##

  environment location: /opt/homebrew/anaconda3/envs/lab1



Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: / WARNING conda.core.path_actions:verify(1051): Unable to create environments file. Path not writable.
  environment location: /Users/cloudjung/.conda/environments.txt

done
Executing transaction: \ WARNING conda.core.envs_manager:register_env(52): Unable to register environment. Path not writable or missing.
  environment location: /opt/homebrew/anaconda3/envs/lab1
  registry file: /Users/cloudjung/.conda/environments.txt
done
#
# To activate this environment, use
#
#     $ conda activate lab1
#
# To deactivate an active environment, use
#
#     $ conda deactivate

conda의 신규 버전이 있어 아래와 같이 update한다.

$ conda update -n base -c defaults conda
$ conda -V
$ conda info

3.tensorflow, tensorflow-metal, jupyterlab 설치

Apple slicon M2 칩을 지원하는 tensorflow를 설치한다. 이떄 conda install과 pip install 명령이 혼동되어 아래 link를 통해 이해했다

conda install 과 pip install의 차이점

conda create -n lab1
conda activate lab1

conda install tensorflow
pip install tensorflow-metal  # conda로 하면 못찾음.
conda install jupyterlab

# jupyterlab을 실행한다.
jupyter-lab

cd /opt/homebrew/anaconda3/envs/lab1/lib/python3.11/site-packages
  • 가상 환경에서 GPU가 사용이 가능한지 확인하는 방법
from tensorflow.python.client import device_lib
print("devices : ", device_lib.list_local_devices())
devices :  [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
  • conda cheatsheet
conda env list
conda install jupyter notebook
conda list
conda deactivate
conda remove --name lab1 --all

참고

error case

➜ ~ conda install tensorflow-metal
Collecting package metadata (current_repodata.json): done
Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  • tensorflow-metal

Current channels:

To search for alternate channels that may provide the conda package you're
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

profile
클라우드쟁이

0개의 댓글