2011. 5. 19. 10:54

Google App Engine 시작 하기 (python)

1) JRE 설치

http://java.sun.com/javase/downloads/index.jsp
에서 Download JRE를 눌러 각 시스템에 맞는 JRE를 설치합니다.
저는 jre-6u25-windows-i586.exe 파일로 설치하였습니다.

2) eclipse 설치

http://www.eclipse.org/downloads에서 eclipse IDE for Java EE Developers 윈도우 버전을 설치합니다.
저는 helios 버전을 사용했으며, C:\eclipse에 압축을 풀었습니다.


그리고, Preference -> General -> Workspace의 Text File Encoding을 UTF-8로 설정합니다.

 


3) python 설치하기

Google App Engine의 python은 2.5.x 버전을 공식적으로 지원합니다.
http://python.org/download/releases/2.5.4

4) python 버전 Google App Engine 설치

http://code.google.com/appengine/downloads.html
그러면 Google App Engine Launcher가 설치됩니다.


eclipse PyDev Plug-In 설치하기

eclipse -> Help -> Install New Software
에서 http://pydev.org/updates 를 선택하여 설치를 진행합니다.

만약, 위 그림과 같이 진행이 되지 않고 계속 pending되는 경우
2011/05/17 - [Google App Engine] - proxy 환경에서 eclipse proxy 설정하기와 같이 proxy 설정이 되어 있었다면,
때에 따라서, proxy 설정을 off (즉, Native)하고, eclipse를 재실행 하면 진행될 수 있습니다.

그리고, Preference -> PyDev -> Interpreter -> PyDev ->Interpreter - Python에
New 하여 C:\Python25\python.exe와 같이 python.exe 경로를 입력합니다.


5) PATH 설정

경우에 따라 PATH가 설정되어야 할 경우가 있습니다.
내컴퓨터 -> 등록정보 -> 고급 시스템 설정 -> 시스템 속정 -> 고급 -> 환경 변수
에서, 사용자 변수쪽의 path 값을 편집하여 다음 항목이 없다면 넣습니다.
;C:\Python25;C:\Program Files\Google\google_appengine\



6) eclipse Google App Engine SDK Plug-In 설치

eclipse -> Help -> Install New Software
에서  http://dl.google.com/eclipse/plugin/3.6 를 선택하여 설치를 진행합니다.



역시나 pending되어 진행이 되지 않는 경우, proxy 설정을 off하고 eclipse.exe를 다시 실행하여 시도해 보시기 바랍니다. 설치가 완료되면 아래와 같이 툴바에 Google 관련 버튼이 생성됩니다.



참고로, 해당 Plug-In은 Google App Engine의 JAVA 개발에 관련된 부분입니다.
즉, Python 개발시에는 특별히 사용되지는 않으나, 일단, 필요한 과정이라 생각하고 포함시켰습니다.
 

7) [옵션] eclipse yedit Plug-In 설치

 

YAML 관련 Plug-In을 설치합니다.
http://dadacoalition.org/yedit 를 선택하여 설치를 진행합니다.
물론, 해당 Plug-In은 설치하지 않아도 무방합니다.

8) Hello,world 만들기

File -> New -> Project -> Pydev -> Pydev Google App Engine Project를 선택합니다.



그다음, Project name에 test003, Grammer Version에 2.5를 선택합니다.



그리고, 마지막으로, Google App Engine Directory에 C:\Program Files\Google\google_appengine
과 같이 google_appengine 경로를 넣으면 아래와 같이 됩니다.



마지막으로 application id를 sample-app-test003, 그리고 Hello World Templete으로 Project를 생성합니다.
application id는 Google App Engine에 등록될 App Id로, 이후 Deploy 할 때 필요합니다.



다음과 같이, Hello, world! greenfish~!!!와 같이 수정합니다.



그럼 다음과 같이 PyDev : Google App Run을 실행시켜 봅니다.



다음과 같이 저장합니다.


그럼 Console에서 아래와 같이 내용이 뜹니다.

INFO     2011-05-18 07:12:09,447 appengine_rpc.py:159] Server: appengine.google.com
INFO     2011-05-18 07:12:09,447 appcfg.py:440] Checking for updates to the SDK.
INFO     2011-05-18 07:12:15,484 appcfg.py:452] Update check failed: <urlopen error timed out>
WARNING  2011-05-18 07:12:15,484 datastore_file_stub.py:657] Could not read datastore data from e:\temp\dev_appserver.datastore
INFO     2011-05-18 07:12:15,484 rdbms_sqlite.py:58] Connecting to SQLite database '' with file 'e:\\temp\\dev_appserver.rdbms'
WARNING  2011-05-18 07:12:15,484 dev_appserver.py:4598] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO     2011-05-18 07:12:15,500 dev_appserver_multiprocess.py:637] Running application sample-app-test003 on port 8080:
http://localhost:8080

만일, SSL을 찾을 수 없다(No ssl package found~...)고 오류가 뜨면, 본 포스트의 9) 부분을 참고하시기 바랍니다.

그럼, http://localhost:8080으로 들어가 보겠습니다.



그럼, Google App Engine Launcher를 이용해 실행(Run)해 보겠습니다.

File -> Add Existing Application을 실행하고,
Path에 src경로를 입력합니다.



그럼, 다음과 같이 Run을 눌러 실행시키고, Logs를 통해 오류가 없나 확인해 봐야 합니다.
역시나 SSL 오류(No ssl package found~...)가 발생한다면, 9) 부분을 참고하시기 바랍니다.



Browse를 누르면, Browser를 바로 실행시켜 줍니다.


8) Deploy(Upload)하여 웹으로 실행하기

eclipse 툴바에 있는 Deploy 버튼은 python이 아닌 JAVA project인 경우 해당됩니다.
즉, python project에서 현재 주어진 방법으론 eclipse에서 Deploy할 수 없습니다.
(물론, http://code.google.com/intl/ko/appengine/docs/python/tools/uploadinganapp.html 를 통해,
coomand나 또 다른 Plug-in을 쉽게 만들 수 있을듯 합니다.)

현재 python project를 업로드 하려면, Google App Engine Launcher를 통하면 됩니다.
앞에서 project를 생성할 때 Application Id를 sample-app-test003로 했기 때문에 아래와 같이 등록 과정을 거치도록 합시다.

참고로,
등록중 사용자 인증 과정이 필요한데, 휴대전화 SMS로 인증을 받았습니다.
전화 번호 입력시(아마도 other country로 했던거 같습니다.) +082 xx xxxx xxxx와 같이 했던걸로 기억됩니다.
즉, 010-1234-5678 이었다면, +082 10 1234 5678과 같이 입력해야 하며,
즉시 SMS 문자 전송을 받았습니다. 역시 Google 답군요 !

https://appengine.google.com/
에 들어가서, "Create Application"을 실행합니다.



그럼 아래와 같이 sample-app-test003으로 "Create Application" 합니다.


그럼 아래 Google App Engine Launcher에서 Deploy 버튼을 눌러 실행합니다.


만약, proxy 환경이라면,
5) PATH 설정에서와 같이, HTTP_PROXY, HTTPS_PROXY에 http://xxx.xxx.xxx.xxx:nnnn 과 같은 형태로 세팅을 사전에 준비해야 합니다.

일단, 아래와 같은 창이 생성되면, Google 계정으로 로그인 합니다.



그러면 아래와 같이 Deploy 성공 로그를 확인할 수 있습니다.

 2011-05-18 18:58:46 Running command: "['C:\\Python25\\pythonw.exe', '-u', 'C:\\Program Files\\Google\\google_appengine\\appcfg.py', '--no_cookies', u'--email=xxxx@xxxx', '--passin', 'update', u'D:\\_work\\eclipse\\test003\\src']"
Application: sample-app-test003; version: 1
Host: appengine.google.com

Starting update of app: sample-app-test003, version: 1
Scanning files on local disk.
Password for
xxxx@xxxx: Cloning 2 application files.
Uploading 2 files and blobs.
Uploaded 2 files and blobs
Precompilation starting.
Precompilation completed.
Starting deployment.
Checking if deployment succeeded.
Will check again in 1 seconds.
Checking if deployment succeeded.
Deployment successful.
Completed update of app: sample-app-test003, version: 1
2011-05-18 18:59:03 (Process exited with code 0)

You can close this window now.


그럼 아래와 같이 브라우저에서 접속이 가능해 집니다.


단, 직전에 등록을 했기 때문에 어느정도 시간이 지나야 접속이 되었습니다. (실제 등록될 때 까지는 HTTP 4xx 오류가 떳습니다.)
뭐 무료로 사용하는 입장에서, 충분히 기다려 줄 수 있습니다.

물론, 소스 보기 하면,
Hello, world!, greenfish~!!
와 같이 정상적인 HTML로 구성되지는 않습니다.

이상으로 Googpe App Engine을 Python으로 개발하고 Deploy하는 과정을 알아 보았으며,
도중 오류가 발생하는데, 이는 아래 부분을 참고하시기 바랍니다.

9) Google App Engine Launcher 오류(Warning) 대처 (SSL, PIL)

Google App Engine은 2.5.x의 pyhon을 지원하는데, 당시의 python은 기본으로 SSL을 지원하지 않습니다.
그래서, 오류가 발생하게 되는데, 사용자가 직접 SSL을 수동으로 설치해 줘야 합니다.

우선, eclipse에서든 Google App Engine Launcher에서든,
WARNING  xxx urlfetch_stub.py:108] No ssl package found. urlfetch will not be able to validate SSL certificates.
같은 오류가 발생한 경우인데, 아래와 같은 스텝으로 진행하여 SSL을 설치합니다.

9-1) SSL 1.15 다운로드
http://pypi.python.org/pypi/ssl/

9-2) build 시도
9-1)의 압축 파일을 풀어, setup.py가 있는 경로로 이동하고, 아래와 같이 빌드 시도
...>python.exe setup.py build
running build
running build_py
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.
하면 위와 같이 빌드가 실패되는데, mingw로 빌드하여 설치 권장하고 있습니다.

9-3) mingw 설치
http://sourceforge.net/projects/mingw/files/
그리고 실행 경로(C:\MinG\bin)를 PATH에 추가합니다. 5)를 참고하시기 바랍니다.

9-4) build 시도 (두번째)
...>python.exe setup.py build -c mingw32
mingw32
running build
running build_py
running build_ext
building 'ssl._ssl2' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Utils\GnuWin32\include -I./
ssl/2.5.1 -IC:\Python25\include -IC:\Python25\PC -c ssl/_ssl2.c -o build\temp.wi
n32-2.5\Release\ssl\_ssl2.o
ssl/_ssl2.c:85:25: fatal error: openssl/rsa.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
와 같이 오류가 발생합니다.

성공 시키기 위해서,

를 다운받아 압축을 풀어야 합니다.

압축을 풀 경로는 ssl 1.15의 setup.py에 hardcode되어 있는데, 다음과 같이 만들어야 합니다.
openssl과 libgw32c 압축 파일 모두 유사한 경로 체계를 가지는데, Merge하여 압축을 풉니다.
그럼 다음과 같은 경로가 됩니다.


즉, C:\Utils\GnuWin32 경로에 Merge하여 압축을 해제합니다.

9-5) build 시도 (세번째) & 설치
...>python.exe setup.py build -c mingw32
running build
running build_py
creating build
creating build\lib.win32-2.5
creating build\lib.win32-2.5\ssl
copying ssl\__init__.py -> build\lib.win32-2.5\ssl
running build_ext
building 'ssl._ssl2' extension
creating build\temp.win32-2.5
creating build\temp.win32-2.5\Release
creating build\temp.win32-2.5\Release\ssl
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Utils\GnuWin32\include -I./
ssl/2.5.1 -IC:\Python25\include -IC:\Python25\PC -c ssl/_ssl2.c -o build\temp.wi
n32-2.5\Release\ssl\_ssl2.o
writing build\temp.win32-2.5\Release\ssl\_ssl2.def
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.5\Release\ssl\_ss
l2.o build\temp.win32-2.5\Release\ssl\_ssl2.def -LC:\Utils\GnuWin32\lib -LC:\Pyt
hon25\libs -LC:\Python25\PCBuild -lssl -lcrypto -lwsock32 -lgdi32 -lgw32c -lole3
2 -luuid -lpython25 -lmsvcr71 -o build\lib.win32-2.5\ssl\_ssl2.pyd -static

와 같이 빌드가 성공되었습니다.

그럼 install을 시도하면,
...>python.exe setup.py install
running install
running build
running build_py
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.
와 같이 오류가 뜨고, -c mingw32를 붙여도 실패됩니다.

즉, 수동으로 복사해야 되는데,
빌드가 성공되면 build\lib.win32-2.5\ssl 경로가 생성되는데,
해당 경로를 복사하여 C:\Python25\Lib\site-packages\에 복사하면 드디어 SSL 설치가 완료 됩니다.

생각보다 SSL의 빌드과정이 여의치 않아, 잘 되지 않는 경우는,

를 사용하시기 바랍니다.

만일, C:\python25에 Python이 설치되었다고 가정한다면, 위 압축 파일을 이용하여
C:\Python25\Lib\site-packages\ssl\__init__.py
C:\Python25\Lib\site-packages\ssl\__init__.pyc
C:\Python25\Lib\site-packages\ssl\_ssl2.pyd
와 같이 구성하시기 바랍니다.

9-6) PIL module 설치
중요 에러는 아니지만,

WARNING  ... dev_appserver.py:4598] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
가 발생한다면, PIL 모듈을 설치하여 제거할 수 있습니다. 물론, python의 PIL(image)관련 API를 사용하지 않는다면, 굳이 설치할 필요는 없어 보입니다.

http://www.pythonware.com/products/pil/
에서
Python Imaging Library 1.1.7 for Python 2.5 (Windows only)
를 다운받아 설치하면 해당 에러 문구는 제거됩니다.