ML - 머신러닝 테스트를 위한 준비과정
AWS EC2에 주피터 개발환경을 세팅
Chapter 2. 머신러닝 처음부터 끝까지
- 환경 세팅하기 목표: AWS EC2에 주피터노트북을 설치하고 웹화면으로 접속하여 테스트환경을 구축함
1-1. EC2 system: ubuntu 20.04 Instance: t2.2xlarge/ 8 CPU / 32 RAM
1-2. python install
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7
ubuntu 18.04 버전에서 install software-properties-common, repository ppa ~ 에 대한 설정 없이 install python3.7을 바로 진행하고 주피터를 설치했더니 아래 같은 어려움이 생겼었다.
ubuntu@ip-10-0-1-208:~$ jupyter --version
/home/ubuntu/.local/lib/python3.6/site-packages/pkg_resources/__init__.py:119: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
PkgResourcesDeprecationWarning,
4.4.0
ubuntu@ip-10-0-1-208:~$ jupyter notebook
/home/ubuntu/.local/lib/python3.6/site-packages/pkg_resources/__init__.py:119: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
PkgResourcesDeprecationWarning,
Error executing Jupyter command 'notebook': [Errno 2] No such file or directory
설치 확인
python3.7 -v
1-3. pip install
sudo apt install python3-pip
1-4. jupyter install
pip3 install jupyter
jupyter --version
Error code:
Command 'jupyter' not found, but can be installed with:
sudo apt install jupyter-core
jupyter-core를 설치한다
ubuntu 20.04 에서 아래같은 에러가 있었는데, 1-5에 환경설정 파일을 생성하니 서버가 잘 구동됐다.
ubuntu@ip-10-0-1-195:~$ jupyter --version
jupyter core : 4.6.3
jupyter-notebook : 6.4.6
qtconsole : 5.2.2
ipython : 7.31.0
ipykernel : 6.6.1
jupyter client : 7.1.0
jupyter lab : not installed
nbconvert : 6.4.0
ipywidgets : 7.6.5
nbformat : 5.1.3
traitlets : 4.3.3
ubuntu@ip-10-0-1-195:~$ jupyter notebook
Traceback (most recent call last):
File "/usr/bin/jupyter", line 11, in <module>
load_entry_point('jupyter-core==4.6.3', 'console_scripts', 'jupyter')()
File "/usr/lib/python3/dist-packages/jupyter_core/command.py", line 247, in main
command = _jupyter_abspath(subcommand)
File "/usr/lib/python3/dist-packages/jupyter_core/command.py", line 133, in _jupyter_abspath
raise Exception(
Exception: Jupyter command `jupyter-notebook` not found.
1-5. jupyter run
환경설정 파일 생성 sha는 위 generate config 시 보여주므로 반드시 복사해둔다.
jupyter notebook --generate-config
환경파일에 vi 로 들어가서 아래처럼 설정을 더한다.
c = get_config()
c.NotebookApp.password = u'sha'
c.NotebookApp.ip = 'EC2-Private IP Address'
c.NotebookApp.notebook_dir = '/home/ubuntu'
jupyter notebook
주피터를 실행할 수 있다.
실행환경 config 파일을 선택하여 실행하고자 할 경우,
jupyter notebook --config jupyter_notebook_config.py
현재 실행중인 주피터 서버 리스팅/ 삭제
jupyter notebook list
jupyter notebook stop 8888
노트북 서버 구동시 패스워드 설정
jupyter notebook password
ec2 환경에서 주피터 서버를 열고 로컬에서 웹브라우저로 접속할 경우, ec2의 퍼블릭 ip와 주피터 서버에 설정한 포트로 접속하면 된다. ec2 에 해당 포트에 대한 오픈 설정은 sg에서 하면 되고..