2017년 10월 7일 토요일

다소 불친절한 라즈베리파이3(Raspberry pi 3)에서 Jupyter notebook/R/Tensorflow 사용하기

동생이 안쓰는 라즈베리파이3를 건네줘서 평소에 눈여겨보던(?) Jupyter Notebook을 설치하고

그위에서 R이 돌아가도록 해보려고 시도중

1. OS설치

적당한 용량의 microSD카드를 준비하고,

Win32 Disk Imager
https://sourceforge.net/projects/win32diskimager/?source=typ_redirect

OS
https://www.raspberrypi.org/downloads/raspbian/

두가지 준비 해서 카드에 OS 설치

2. 기본설정

X윈도우에서 ssh 및 vnc를 Enable 로 설정하여, 접속 가능하게 하고

터미널 접속 암호 설정

3. miniconda3 설치

::업뎃부터 해주자

sudo apt-get update
sudo apt-get upgrade

::파이썬 설치하고..(아마 설치되어있을 가능성이 높음)

sudo apt-get install python-pip
sudo apt-get install ipython
sudo apt-get install ipython3

::matplot이 필요하다고 한다

sudo apt-get install python3-matplotlib

::아나콘다는 무거워서 미니콘다로 설치해야한다고 한다(http://yongyong-e.tistory.com/39)

$ wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
$ sudo md5sum Miniconda3-latest-Linux-armv7l.sh
$ sudo /bin/bash Miniconda3-latest-Linux-armv7l.sh

::홈디렉토리로 꼭 PATH변경을 해줘야할 것 같다

/home/<계정명>/miniconda3$:PATH

$ conda search 로 설치가능 패키지 확인
$ conda install bitarray

4. Tensorflow 설치(https://github.com/samjabrahams/tensorflow-on-raspberry-pi)

::라즈베리파이용 텐서플로우 설치(왜인지 3.3버전은 설치가 안된다)

# For Python 2.7
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.11.0/tensorflow-0.11.0-cp27-none-linux_armv7l.whl
$ sudo pip install tensorflow-0.11.0-cp27-none-linux_armv7l.whl

# For Python 3.3+
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.11.0/tensorflow-0.11.0-py3-none-any.whl
$ sudo pip3 install tensorflow-0.11.0-py3-none-any.whl

::여기까지는 콘솔에서 텐서플로우 사용 가능, but Jupyter에서는 아래 방법이 필요

::권한주기

sudo chown -Rc <계정명>:<계정이속한 그룹> /home/<계정명>/miniconda3


::Tensorflow를 위한 컨테이너 생성(http://flyingdcat4.tistory.com/77)

$ conda create -n tensorflow python=2.7
$ source activate tensorflow

::컨테이너 안에 텐서플로우와 ipython, jupyter 설치(조금 시간이 걸림)

$ pip install —ignore-installed tensorflow-0.11.0-cp27-none-linux_armv7l.whl
$ conda install ipython
$ pip install jupyter

::jupyter는 왜인지 conda로 설치가 안된다...

::Tensorflow용 커널 생성

$ ipython kernelspec install-self —user
$ mkdir -p ~/.ipython/kernels
$ mv ~/.local/share/jupyter/kernels/python2 ~/.ipython/kernels/tfkernel

::커널이름 바꿔주기(json파일 수정)

cd ~/.ipython/kernels/tfkernel/
vi kernel.json



5. Jupyter notebook 설치 및 환경설정(http://goodtogreate.tistory.com/entry/IPython-Notebook-설치방법)

::설치(위에서 했으면 생략 가능)

pip install jupyter

::백그라운드에서 서버로 돌아가게 하기위한 작업

$jupyter notebook —generate-config

.py파일 생성후


::웹접속용 암호 생성

ipython 실행

In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: ‘블라블라’

$nano /jupyter_notebook_config.py

::파일을 열어서,

c.NotebookApp.ip = ‘*’
c.NotebookApp.password = ‘블라블라’
c.NotebookApp.open_browser = False

찾아서 수정

ip:8888/ 접속하면 일단 python 사용가능

6. R설치하기

/etc/apt/sources.list 열어서

deb http://archive.raspbian.org/raspbian
혹은
deb http://mirrordirector.raspbian.org/raspbian/ stretch main
추가

$sudo apt-get install r-base r-base-core r-base-dev

7. R과 Jupyter 연동하기(https://huklee.github.io/2017/04/15/062.how-to-run-R-in-jupyter-IRkernel/)

::추가설치(오류뿜뿜)
$sudo apt-get libssl-dev
$sudo apt-get libcurl4-openssl-dev

::IRKernel 패키지 설치

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec(user = FALSE)

8. 실행

석세스풀!!

댓글 없음:

댓글 쓰기