Middleware (오픈소스 활용-7) Flask 1장 - Flask 설치 및 python (2.7 -> 3.6) 업그레이드 방법
페이지 정보
작성자 미들웨어 아이디로 검색 전체게시물 댓글 0건 조회 5,020회 좋아요 0회 작성일 22-06-08 16:57본문
안녕하세요. "미들웨어" 입니다.
이번엔 파이선 웹서버인 Flask (플라스크)에 대해 알아보고 설치해보는 과정을 진행해보겠습니다.
Flask 란 무엇인지, Flask 플라스크를 설치하고 어떻게 활용하는지 궁금하네요.
내용이 많은 관계로 1장, 2장으로 나눠서 진행하도록 하겠습니다.
1. Flask 란?
- Flask는 "파이썬 웹 어플리케이션 프레임워크" 입니다.
- 플라스크(Flask)는 파이썬으로 작성된 마이크로 웹 프레임워크의 하나로, Werkzeug 툴킷과 Jinja2 템플릿 엔진에 기반을 둔다
- 플라스크는 특별한 도구나 라이브러리가 필요 없기 때문에 마이크로 프레임워크라 부른다.
- 위키 백과에 정의된 Flask 설명
https://ko.wikipedia.org/wiki/%ED%94%8C%EB%9D%BC%EC%8A%A4%ED%81%AC_(%EC%9B%B9_%ED%94%84%EB%A0%88%EC%9E%84%EC%9B%8C%ED%81%AC)
아래 샘플은 Hello World!를 출력하는 웹 애플리케이션 샘플입니다.
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run() |
자... 여튼. Flask란 이런건데, 이것을 사용하기 위해서는 일단 Python 가 필요합니다.
버전이 2.x 3.x 이 있는데, 저흰 이럴때 최신버전으로 진행을 합니다.. 그래야 추후 업그레이드 이슈가 발생하지 않기 때문이조.
그럼 이제 Python 설치 및 업그레이드에 대해 알아보도록 하겠습니다.
2. Python 업그레이드 (version2.7 => 3.6)
- python 버전 확인
[root@weblogic-test ~]# python Python 2.7.5 (default, Mar 12 2021, 14:55:44) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44.0.3)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
- 파이선 버전 업그레이드 [root@weblogic-test ~]# yum install python3 ..... (생략) ======================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================= Updating: python3 x86_64 3.6.8-18.0.5.el7 ol7_latest 70 k Updating for dependencies: python3-libs x86_64 3.6.8-18.0.5.el7 ol7_latest 6.9 M Transaction Summary ======================================================================================================================================= - 설치 확인 경로 : /usr/bin lrwxrwxrwx. 1 root root 7 Jul 23 2021 python -> python2 lrwxrwxrwx. 1 root root 9 Jul 23 2021 python2 -> python2.7 -rwxr-xr-x. 1 root root 7144 Mar 13 2021 python2.7 lrwxrwxrwx. 1 root root 9 May 31 15:26 python3 -> python3.6 -rwxr-xr-x. 2 root root 11336 Nov 19 2021 python3.6 - 파이선 3버전으로 심볼릭 링크 변경 [root@weblogic-test bin]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/maven/bin [root@weblogic-test bin]# ln -s /usr/bin/python3.6 /usr/local/bin/python [root@weblogic-test bin]# ls -la /usr/local/bin/python lrwxrwxrwx. 1 root root 18 May 31 15:36 /usr/local/bin/python -> /usr/bin/python3.6 |
3. pip 버전 업그레이드
[root@weblogic-test ~]# python3.6 -m pip install --upgrade pip WARNING: Running pip install with root privileges is generally not a good idea. Try `__main__.py install --user` instead. Collecting pip Downloading https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB) 100% |████████████████████████████████| 1.7MB 597kB/s Installing collected packages: pip Successfully installed pip-21.3.1
[root@weblogic-test ~]# which pip3.6 /usr/local/bin/pip3.6
[root@weblogic-test ~]# python3.6 -m pip -V pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6) |
4. virtualenv 가상환경 생성
- 파이썬에서 가상 환경(virtual environment)은 하나의 PC에서 프로젝트 별로 독룁된 파이썬 실행 환경(runtime/interpreter)을 사용할 수 있도록 해줍니다
- venv 모듈은 virtualenv의 경량화된 모듈입니다.
[root@weblogic-test ~]# pip install virtualenv Collecting virtualenv Downloading virtualenv-20.14.1-py2.py3-none-any.whl (8.8 MB) |████████████████████████████████| 8.8 MB 24.0 MB/s Collecting importlib-resources>=1.0 Downloading importlib_resources-5.4.0-py3-none-any.whl (28 kB) Collecting filelock<4,>=3.2 Downloading filelock-3.4.1-py3-none-any.whl (9.9 kB) Collecting distlib<1,>=0.3.1 Downloading distlib-0.3.4-py2.py3-none-any.whl (461 kB) |████████████████████████████████| 461 kB 30.1 MB/s Collecting platformdirs<3,>=2 Downloading platformdirs-2.4.0-py3-none-any.whl (14 kB) Requirement already satisfied: six<2,>=1.9.0 in /usr/lib/python3.6/site-packages (from virtualenv) (1.14.0) Requirement already satisfied: importlib-metadata>=0.12 in /usr/local/lib/python3.6/site-packages (from virtualenv) (4.8.3) Requirement already satisfied: typing-extensions>=3.6.4 in /usr/lib/python3.6/site-packages (from importlib-metadata>=0.12->virtualenv) (3.7.4.2) Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/site-packages (from importlib-metadata>=0.12->virtualenv) (3.6.0) Installing collected packages: platformdirs, importlib-resources, filelock, distlib, virtualenv Successfully installed distlib-0.3.4 filelock-3.4.1 importlib-resources-5.4.0 platformdirs-2.4.0 virtualenv-20.14.1 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[root@weblogic-test ~]# virtualenv venv created virtual environment CPython3.6.8.final.0-64 in 747ms creator CPython3Posix(dest=/root/venv, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv) added seed packages: pip==21.3.1, setuptools==59.6.0, wheel==0.37.1 activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator |
- 가상환경 라이브러리 venv 폴더 생성 확인
[root@weblogic-test venv]# pwd
/root/venv
[root@weblogic-test venv]# ll
total 8
drwxr-xr-x. 2 root root 4096 May 31 15:53 bin
drwxr-xr-x. 3 root root 23 May 31 15:53 lib
drwxr-xr-x. 3 root root 23 May 31 15:53 lib64
-rw-r--r--. 1 root root 200 May 31 15:53 pyvenv.cfg
5. Flask 설치
- Flask 인스톨
진행 중 ERROR 발생이 됐지만, 이건 Flask와는 상관없는 ORacle OCI VM의 라이브러리 버전 호환성 이슈입니다.
[root@weblogic-test ~]# pip install flask Collecting flask Downloading Flask-2.0.3-py3-none-any.whl (95 kB) |████████████████████████████████| 95 kB 6.3 MB/s Collecting Jinja2>=3.0 Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB) |████████████████████████████████| 133 kB 20.3 MB/s Collecting Werkzeug>=2.0 Downloading Werkzeug-2.0.3-py3-none-any.whl (289 kB) |████████████████████████████████| 289 kB 20.2 MB/s Collecting itsdangerous>=2.0 Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB) Collecting click>=7.1.2 Downloading click-8.0.4-py3-none-any.whl (97 kB) |████████████████████████████████| 97 kB 9.8 MB/s Collecting importlib-metadata Downloading importlib_metadata-4.8.3-py3-none-any.whl (17 kB) Collecting MarkupSafe>=2.0 Downloading MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB) Collecting dataclasses Downloading dataclasses-0.8-py3-none-any.whl (19 kB) Requirement already satisfied: typing-extensions>=3.6.4 in /usr/lib/python3.6/site-packages (from importlib-metadata->click>=7.1.2->flask) (3.7.4.2) Collecting zipp>=0.5 Downloading zipp-3.6.0-py3-none-any.whl (5.3 kB) Installing collected packages: zipp, MarkupSafe, importlib-metadata, dataclasses, Werkzeug, Jinja2, itsdangerous, click, flask Attempting uninstall: click Found existing installation: click 6.7 Uninstalling click-6.7: Successfully uninstalled click-6.7 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. oci-cli 3.5.1 requires pyOpenSSL==19.1.0, which is not installed. oci-cli 3.5.1 requires click==7.1.2, but you have click 8.0.4 which is incompatible. oci-cli 3.5.1 requires six>=1.15.0, but you have six 1.14.0 which is incompatible.
Successfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.3 click-8.0.4 dataclasses-0.8 flask-2.0.3 importlib-metadata-4.8.3 itsdangerous-2.0.1 zipp-3.6.0 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv |
이걸로 Flask 설치는 완료됐습니다..
그럼 2주후에 설치된 Flask 를 테스트 하는 방법에 대해 정리해보도록 하겠습니다.
그럼... 열공하세요~
댓글목록
등록된 댓글이 없습니다.