본문 바로가기
Study/Deep Learning

맥북 M1 - Tensorflow 설치하기

by uiydlop 2022. 1. 11.

맥북 m1에 텐서플로우를 설치하려면 윈도우나 그냥 맥이랑 다르게, 다른 방법을 거쳐야 한다 (좀 많이 까다롭^^)
나도 멋 모르고 아나콘다 깔고 그냥 터미널 열어서 pip install tensorflow 했다가 import tensorflow as tf 안돼서 식겁 ㅎㅎ


그래서 나처럼 헛수고 안 하게 m1에 tensorflow 설치하는 방법을 공유 !!

참고영상1 : https://youtu.be/cWkoiky4fqs
참고영상2 : https://youtu.be/Ws0PSp-puU0

우선 나는 위 두 영상을 모두 참고하여 설치하였다.


1. 맥북 터미널 open 해서 xcode 설치

xcode-select --install

2. miniforge3 설치해주기

- conda 사용하기 위해선 필요하므로 아래 링크에 들어가서

https://github.com/conda-forge/miniforge

 

GitHub - conda-forge/miniforge: A conda-forge distribution.

A conda-forge distribution. Contribute to conda-forge/miniforge development by creating an account on GitHub.

github.com

Miniforge3-MacOSX-arm64 클릭해 다운로드하여준다.

 

(다운로드 폴더에 위치해있는 것을 볼 수 있음)

cd Downloads ls

 

다운로드 폴더로 들어가서 bash 명령을 이용하여 파일을 실행해준다.

bash Miniforge3-MacOSX-arm64.sh

 


3. 새 터미널 open 하여 가상 환경 설치


conda create -n (가상 환경 이름)
conda create --name (가상 환경 이름)

conda create -n tensor

 

둘 중 아무거나 사용하여 가상 환경을 만들어주고

conda activate tensor


가상 환경에 진입
한다.

진입했을 경우, (가상 환경) <- 이렇게 앞에 나타나야 진입 성공한 것이다.

이제 파이썬을 설치해주는데 3.8x 버전을 사용하는 것이 좋다.

conda install -y python==3.8 
conda install -y pandas matplotlib scikit-learn jupyter

나머지도 다 설치해주면 된다.



이제부터 가장 중요한 작업들이다.

 

4. Tensorflow-macos 다운로드


https://github.com/apple/tensorflow_macos
위 링크(apple github)로 들어가도 되지만 releases 찾기 어려우므로
https://github.com/apple/tensorflow_macos/releases
⬆️ 이 링크로 바로 가서

 

tensorflow_macos-0.1alpha2.tar.gz 다운로드하여서 압축을 풀어준다. (다운로드 폴더 가서 해당 압축 파일 더블클릭하면 됨)

tar xvf 명령으로 압축 풀어도 가능

압축 푼 tensorflow-macos로 들어가 arm64 폴더

⬆️ 위 파일들이 필요한 것이다. ⬆️


5. Tensorflow 설치 ⭐️⭐️⭐️⭐️⭐️

(가상환경 진입 상태임. 나가 졌다면 다시 conda activate tensor 해서 진입 )



1) 그대로 입력 enter

 

pip install --force pip==20.2.4 wheel setuptools cached-property six

 

2) 입력 + 파일 첨부 enter

 

pip install --upgrade --no-dependencies --force

--force 까지만 치고 4개 파일을 마우스로 드래그해서 옮겨주면 된다. (마지막 꺼는 나중에 ,, 3번째 backup 파일은 필요 없음)

 

3) 그대로 입력 enter


pip install absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard

pip install absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard

 

4) 입력 + 파일 첨부 enter

 

pip install --upgrade --force --no-dependencies

2번이랑 동일한 방법으로, 남은 마지막 파일을 넣어준다.

이렇게 하면 설치가 다 된 것이다!!!!!!!!

 

conda list 해서 확인해보면

tensorflow가 잘 설치되었다. 👏👏👏👏👏

ipython 들어가서 import tensorflow as tf 해도 문제없음!

이제 jupyter notebook 들어가서 텐서플로우 작업 ~~ 등등하면 된다. ☺️

댓글