[02주차] Python 시작

Sung-E-Gkoght·2022년 11월 13일
0

HYAI - Python class

목록 보기
6/17

0-1. Jupyter notebook 설치

만약 파이썬을 설치했다면, Jupyter notebook을 설치할 수 있습니다.

cmd를 실행해서 아래를 입력합니다.

pip install notebook

기다리면 설치가 됩니다.

(과정. 그저 넣어본 내용이고, 읽지 말아주세요... 아래로 넘기면 jupyter notebook 실행이 나옵니다.)

Microsoft Windows [Version 10.0.19043.2251]
(c) Microsoft Corporation. All rights reserved.

C:\Users\user_name>pip install notebook
Collecting notebook
  Downloading notebook-6.5.2-py3-none-any.whl (439 kB)
     ---------------------------------------- 439.1/439.1 kB 6.8 MB/s eta 0:00:00
Collecting Send2Trash>=1.8.0
  Downloading Send2Trash-1.8.0-py3-none-any.whl (18 kB)
Collecting prometheus-client
  Downloading prometheus_client-0.15.0-py3-none-any.whl (60 kB)
     ---------------------------------------- 60.1/60.1 kB 3.3 MB/s eta 0:00:00
Collecting terminado>=0.8.3
  Downloading terminado-0.17.0-py3-none-any.whl (16 kB)
Collecting tornado>=6.1
  Downloading tornado-6.2-cp37-abi3-win_amd64.whl (425 kB)
     ---------------------------------------- 425.3/425.3 kB 8.8 MB/s eta 0:00:00
Collecting jupyter-core>=4.6.1
  Downloading jupyter_core-5.0.0-py3-none-any.whl (91 kB)
     ---------------------------------------- 91.1/91.1 kB ? eta 0:00:00
Collecting ipython-genutils
  Downloading ipython_genutils-0.2.0-py2.py3-none-any.whl (26 kB)
Collecting nbconvert>=5
  Downloading nbconvert-7.2.4-py3-none-any.whl (273 kB)
     ---------------------------------------- 273.2/273.2 kB 17.5 MB/s eta 0:00:00
Collecting traitlets>=4.2.1
  Downloading traitlets-5.5.0-py3-none-any.whl (107 kB)
     ---------------------------------------- 107.4/107.4 kB 6.5 MB/s eta 0:00:00
Collecting jinja2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ---------------------------------------- 133.1/133.1 kB 7.7 MB/s eta 0:00:00
Collecting argon2-cffi
  Downloading argon2_cffi-21.3.0-py3-none-any.whl (14 kB)
Collecting nest-asyncio>=1.5
  Downloading nest_asyncio-1.5.6-py3-none-any.whl (5.2 kB)
Collecting pyzmq>=17
  Downloading pyzmq-24.0.1-cp310-cp310-win_amd64.whl (992 kB)
     ---------------------------------------- 992.7/992.7 kB 10.5 MB/s eta 0:00:00
Collecting jupyter-client>=5.3.4
  Downloading jupyter_client-7.4.5-py3-none-any.whl (132 kB)
     ---------------------------------------- 132.3/132.3 kB ? eta 0:00:00
Collecting ipykernel
  Downloading ipykernel-6.17.1-py3-none-any.whl (138 kB)
     ---------------------------------------- 138.6/138.6 kB ? eta 0:00:00
Collecting nbclassic>=0.4.7
  Downloading nbclassic-0.4.8-py3-none-any.whl (9.8 MB)
     ---------------------------------------- 9.8/9.8 MB 10.4 MB/s eta 0:00:00
Collecting nbformat
  Downloading nbformat-5.7.0-py3-none-any.whl (77 kB)
     ---------------------------------------- 77.1/77.1 kB 4.5 MB/s eta 0:00:00
Collecting python-dateutil>=2.8.2
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ---------------------------------------- 247.7/247.7 kB 7.7 MB/s eta 0:00:00
Collecting entrypoints
  Downloading entrypoints-0.4-py3-none-any.whl (5.3 kB)
Collecting platformdirs
  Downloading platformdirs-2.5.4-py3-none-any.whl (14 kB)
Collecting pywin32>=1.0
  Downloading pywin32-305-cp310-cp310-win_amd64.whl (12.1 MB)
     ---------------------------------------- 12.1/12.1 MB 7.4 MB/s eta 0:00:00
Collecting notebook-shim>=0.1.0
  Downloading notebook_shim-0.2.2-py3-none-any.whl (13 kB)
Collecting jupyter-server>=1.8
  Downloading jupyter_server-1.23.1-py3-none-any.whl (346 kB)
     ---------------------------------------- 346.4/346.4 kB 21.0 MB/s eta 0:00:00
Collecting nbclient>=0.5.0
  Downloading nbclient-0.7.0-py3-none-any.whl (71 kB)
     ---------------------------------------- 71.9/71.9 kB 3.9 MB/s eta 0:00:00
Collecting pygments>=2.4.1
  Downloading Pygments-2.13.0-py3-none-any.whl (1.1 MB)
     ---------------------------------------- 1.1/1.1 MB 8.7 MB/s eta 0:00:00
Collecting beautifulsoup4
  Downloading beautifulsoup4-4.11.1-py3-none-any.whl (128 kB)
     ---------------------------------------- 128.2/128.2 kB ? eta 0:00:00
Collecting pandocfilters>=1.4.1
  Downloading pandocfilters-1.5.0-py2.py3-none-any.whl (8.7 kB)
Collecting markupsafe>=2.0
  Downloading MarkupSafe-2.1.1-cp310-cp310-win_amd64.whl (17 kB)
Collecting tinycss2
  Downloading tinycss2-1.2.1-py3-none-any.whl (21 kB)
Collecting packaging
  Downloading packaging-21.3-py3-none-any.whl (40 kB)
     ---------------------------------------- 40.8/40.8 kB 2.0 MB/s eta 0:00:00
Collecting defusedxml
  Downloading defusedxml-0.7.1-py2.py3-none-any.whl (25 kB)
Collecting jupyterlab-pygments
  Downloading jupyterlab_pygments-0.2.2-py2.py3-none-any.whl (21 kB)
Collecting mistune<3,>=2.0.3
  Downloading mistune-2.0.4-py2.py3-none-any.whl (24 kB)
Collecting bleach
  Downloading bleach-5.0.1-py3-none-any.whl (160 kB)
     ---------------------------------------- 160.9/160.9 kB 9.4 MB/s eta 0:00:00
Collecting fastjsonschema
  Downloading fastjsonschema-2.16.2-py3-none-any.whl (22 kB)
Collecting jsonschema>=2.6
  Downloading jsonschema-4.17.0-py3-none-any.whl (83 kB)
     ---------------------------------------- 83.8/83.8 kB 4.6 MB/s eta 0:00:00
Collecting pywinpty>=1.1.0
  Downloading pywinpty-2.0.9-cp310-none-win_amd64.whl (1.4 MB)
     ---------------------------------------- 1.4/1.4 MB 8.9 MB/s eta 0:00:00
Collecting argon2-cffi-bindings
  Downloading argon2_cffi_bindings-21.2.0-cp36-abi3-win_amd64.whl (30 kB)
Collecting matplotlib-inline>=0.1
  Downloading matplotlib_inline-0.1.6-py3-none-any.whl (9.4 kB)
Collecting psutil
  Downloading psutil-5.9.4-cp36-abi3-win_amd64.whl (252 kB)
     ---------------------------------------- 252.5/252.5 kB 7.6 MB/s eta 0:00:00
Collecting ipython>=7.23.1
  Downloading ipython-8.6.0-py3-none-any.whl (761 kB)
     ---------------------------------------- 761.1/761.1 kB 9.6 MB/s eta 0:00:00
Collecting debugpy>=1.0
  Downloading debugpy-1.6.3-cp310-cp310-win_amd64.whl (4.6 MB)
     ---------------------------------------- 4.6/4.6 MB 10.5 MB/s eta 0:00:00
Collecting decorator
  Downloading decorator-5.1.1-py3-none-any.whl (9.1 kB)
Collecting colorama
  Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting jedi>=0.16
  Downloading jedi-0.18.1-py2.py3-none-any.whl (1.6 MB)
     ---------------------------------------- 1.6/1.6 MB 10.0 MB/s eta 0:00:00
Collecting pickleshare
  Downloading pickleshare-0.7.5-py2.py3-none-any.whl (6.9 kB)
Collecting prompt-toolkit<3.1.0,>3.0.1
  Downloading prompt_toolkit-3.0.32-py3-none-any.whl (382 kB)
     ---------------------------------------- 382.8/382.8 kB 12.0 MB/s eta 0:00:00
Collecting stack-data
  Downloading stack_data-0.6.1-py3-none-any.whl (24 kB)
Collecting backcall
  Downloading backcall-0.2.0-py2.py3-none-any.whl (11 kB)
Collecting pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0
  Downloading pyrsistent-0.19.2-cp310-cp310-win_amd64.whl (62 kB)
     ---------------------------------------- 62.8/62.8 kB 3.5 MB/s eta 0:00:00
Collecting attrs>=17.4.0
  Downloading attrs-22.1.0-py2.py3-none-any.whl (58 kB)
     ---------------------------------------- 58.8/58.8 kB ? eta 0:00:00
Collecting websocket-client
  Downloading websocket_client-1.4.2-py3-none-any.whl (55 kB)
     ---------------------------------------- 55.3/55.3 kB ? eta 0:00:00
Collecting anyio<4,>=3.1.0
  Downloading anyio-3.6.2-py3-none-any.whl (80 kB)
     ---------------------------------------- 80.6/80.6 kB 4.4 MB/s eta 0:00:00
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting cffi>=1.0.1
  Downloading cffi-1.15.1-cp310-cp310-win_amd64.whl (179 kB)
     ---------------------------------------- 179.1/179.1 kB 10.6 MB/s eta 0:00:00
Collecting soupsieve>1.2
  Downloading soupsieve-2.3.2.post1-py3-none-any.whl (37 kB)
Collecting webencodings
  Downloading webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting pyparsing!=3.0.5,>=2.0.2
  Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB)
     ---------------------------------------- 98.3/98.3 kB 5.5 MB/s eta 0:00:00
Collecting sniffio>=1.1
  Downloading sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting idna>=2.8
  Downloading idna-3.4-py3-none-any.whl (61 kB)
     ---------------------------------------- 61.5/61.5 kB 3.2 MB/s eta 0:00:00
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     ---------------------------------------- 118.7/118.7 kB 6.8 MB/s eta 0:00:00
Collecting parso<0.9.0,>=0.8.0
  Downloading parso-0.8.3-py2.py3-none-any.whl (100 kB)
     ---------------------------------------- 100.8/100.8 kB ? eta 0:00:00
Collecting wcwidth
  Downloading wcwidth-0.2.5-py2.py3-none-any.whl (30 kB)
Collecting asttokens>=2.1.0
  Downloading asttokens-2.1.0-py2.py3-none-any.whl (26 kB)
Collecting pure-eval
  Downloading pure_eval-0.2.2-py3-none-any.whl (11 kB)
Collecting executing>=1.2.0
  Downloading executing-1.2.0-py2.py3-none-any.whl (24 kB)
Installing collected packages: webencodings, wcwidth, Send2Trash, pywin32, pure-eval, pickleshare, mistune, ipython-genutils, fastjsonschema, executing, backcall, websocket-client, traitlets, tornado, tinycss2, soupsieve, sniffio, six, pyzmq, pywinpty, pyrsistent, pyparsing, pygments, pycparser, psutil, prompt-toolkit, prometheus-client, platformdirs, parso, pandocfilters, nest-asyncio, markupsafe, jupyterlab-pygments, idna, entrypoints, defusedxml, decorator, debugpy, colorama, attrs, terminado, python-dateutil, packaging, matplotlib-inline, jupyter-core, jsonschema, jinja2, jedi, cffi, bleach, beautifulsoup4, asttokens, anyio, stack-data, nbformat, jupyter-client, argon2-cffi-bindings, nbclient, ipython, argon2-cffi, nbconvert, ipykernel, jupyter-server, notebook-shim, nbclassic, notebook
Successfully installed Send2Trash-1.8.0 anyio-3.6.2 argon2-cffi-21.3.0 argon2-cffi-bindings-21.2.0 asttokens-2.1.0 attrs-22.1.0 backcall-0.2.0 beautifulsoup4-4.11.1 bleach-5.0.1 cffi-1.15.1 colorama-0.4.6 debugpy-1.6.3 decorator-5.1.1 defusedxml-0.7.1 entrypoints-0.4 executing-1.2.0 fastjsonschema-2.16.2 idna-3.4 ipykernel-6.17.1 ipython-8.6.0 ipython-genutils-0.2.0 jedi-0.18.1 jinja2-3.1.2 jsonschema-4.17.0 jupyter-client-7.4.5 jupyter-core-5.0.0 jupyter-server-1.23.1 jupyterlab-pygments-0.2.2 markupsafe-2.1.1 matplotlib-inline-0.1.6 mistune-2.0.4 nbclassic-0.4.8 nbclient-0.7.0 nbconvert-7.2.4 nbformat-5.7.0 nest-asyncio-1.5.6 notebook-6.5.2 notebook-shim-0.2.2 packaging-21.3 pandocfilters-1.5.0 parso-0.8.3 pickleshare-0.7.5 platformdirs-2.5.4 prometheus-client-0.15.0 prompt-toolkit-3.0.32 psutil-5.9.4 pure-eval-0.2.2 pycparser-2.21 pygments-2.13.0 pyparsing-3.0.9 pyrsistent-0.19.2 python-dateutil-2.8.2 pywin32-305 pywinpty-2.0.9 pyzmq-24.0.1 six-1.16.0 sniffio-1.3.0 soupsieve-2.3.2.post1 stack-data-0.6.1 terminado-0.17.0 tinycss2-1.2.1 tornado-6.2 traitlets-5.5.0 wcwidth-0.2.5 webencodings-0.5.1 websocket-client-1.4.2

C:\Users\user_name>

실행은 아래를 입력하는 것으로 가능합니다.

jupyter notebook

(참고)

C:\Users\user_name>jupyter notebook
[I 15:04:31.635 NotebookApp] Writing notebook server cookie secret to C:\Users\user_name\AppData\Roaming\jupyter\runtime\notebook_cookie_secret
[I 15:04:33.074 NotebookApp] Serving notebooks from local directory: C:\Users\hjkl2
[I 15:04:33.075 NotebookApp] Jupyter Notebook 6.5.2 is running at:
[I 15:04:33.075 NotebookApp] http://localhost:8888/?token=ee6bfb9dcecb9e63c8124d8406478895a85d0d69271af218
[I 15:04:33.075 NotebookApp]  or http://127.0.0.1:8888/?token=ee6bfb9dcecb9e63c8124d8406478895a85d0d69271af218
[I 15:04:33.075 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:04:33.207 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/hjkl2/AppData/Roaming/jupyter/runtime/nbserver-22508-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=ee6bfb9dcecb9e63c8124d8406478895a85d0d69271af218
     or http://127.0.0.1:8888/?token=ee6bfb9dcecb9e63c8124d8406478895a85d0d69271af218

그러면 다음과 같이 실행이 됩니다.

중요: DOS창(cmd) 끄시면 안됩니다! 여러분의 cmd를 보시면 커서가 깜빡이고 있는 걸 확인하실 수 있는데, 이건 계속 실행중이라는 의미입니다! "웹 브라우저에서 켜졌으니 이건 꺼야지" 하시면 jupyter notebook도 함께 종료됩니다!

jupyter notebook은 기본값으로 설정된 웹 브라우저에서 열립니다.
기본 웹 브라우저 설정은 다음과 같습니다.

  1. 기본 앱 검색

  2. 웹 브라우저 클릭

원하시는 웹 브라우저를 클릭하시면 됩니다. 저는 현재 Chrome를 사용하고 있네요.

(주피터 노트북(Jupyter notebook) 구글 크롬으로 설정하는 3가지 방법)

0-2. Jupyter notebook 시작 준비

우선 앞으로 작성할 Python코드를 모아놓을 새로운 폴더를 하나 만듭니다.

만드는 이유는 Jupyter notebook의 시작 경로가

C:\Users\user_name

입니다. 사용자 경로에 코드들이 하나둘씩 쌓이게 되면, 나중에 꽤 불편해지기 때문입니다. 이유가 이뿐만은 아닙니다. Jupyter notebook에서 작업하는 내용은 비록 웹 브라우저 상에서 수행하지만 실제 여러분의 컴퓨터와 연결되어 있습니다. 다시 말해 파일을 잘못 삭제하면 여러분의 컴퓨터에 저장되어 있는 바로 그 파일이 삭제되어버립니다. 그러니 모든 작업을 따로 만들어둔 폴더에서 수행하면 컴퓨터를 망가뜨릴 일도 없지 않을까요?

  1. 우측에 보시면 new 항목이 있는데, 거기서 폴더를 만들 수 있습니다.

  2. 그러면 Untitled folder가 아래 파일들 사이에 생기는데, 찾기 어려울 땐 "몇 초 전" 또는 "몇 분 전"에 생긴 파일을 찾아보시면 될 것 같습니다!

  3. 파일명 좌측의 체크박스를 클릭하면 위에 Rename이 생겨난 것을 볼 수 있습니다.

  4. 클릭하면 이렇게 뜨는데, 저는 HYAI Python으로 수정하도록 하겠습니다.

그런데 사실 앞서 Jupyter notebook과 여러분의 컴퓨터는 연결되어 있다는 식의 말을 했습니다. 그렇다면 여러분이 만약 본인의 컴퓨터에서 시작 경로에 들어가 폴더를 만들어도 되지 않을까요?


시작 경로에 들어갔더니 HYAI Python이라는 이름의 폴더가 있는 것을 볼 수 있습니다.

HYAI Python2를 새로 만들고, HYAI Python를 HYAI Python3로 이름을 바꾸어보았습니다.

그리고 나서 Jupyter notebook에서 확인을 해보았더니 다음과 같이 나오네요!

오늘 2주차 연습문제는 HYAI Python2에, 3주차 연습문제는 HYAI Python3에 저장하도록 하겠습니다:)

Python 프로그램 작성은 New 버튼을 클릭하면 Python3을 누르시면 가능합니다!

이제 2주차 본격적인 내용을 살펴보도록 하겠습니다!

[[02주차] 기본 문법()]
[02주차] 자료형
[[02주차] 조건문()]
[[02주차] 반복문()]

profile
Sung-E-Gkoght

0개의 댓글