Google App Engine で Python 2.5からPython 2.7へ切り替える

Google App Engineのダッシュボードに以下のようなメッセージがずっと表示されていた。

A version of this application is using the Python 2.5 runtime, which is deprecated!
The application should be updated to the Python 2.7 runtime as soon as possible, which offers performance improvements and many new features. Learn how simple it is to migrate your application to Python 2.7.

Python 2.5からPython 2.7へできるだけ早く切り替えるように、というメッセージ。面倒なので放置していたけど、思い切って移転作業をしてみた。結論から書くと思ったより簡単。調べ物の時間も入れて30分位でできた。

以下、Google App Engine で Python 2.5からPython 2.7へ切り替える方法

まずメインのプログラムファイル。

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

これを削除して

import webapp2

とする。他のインポートしているものなどはそのままで大丈夫だった。

あと、クラス部分の

webapp.RequestHandler

webapp2.RequestHandler

とする

こういう作業はDevasというファイル置換ソフトを使って一括置換。

一番下の部分は

app = webapp2.WSGIApplication([(‘/’, MainPage)],
debug=True)

のようにappとする。(前はapplicationとしてた)

def main():
run_wsgi_app(application)

if __name__ == “__main__”:
main()

は要らないので全部削除。

app.yamlファイルは、

application: helloworld
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:

として、次に

– url: /test
script: test.app

のように、拡張子をpyからappに変更。

それと

builtins:
– datastore_admin: on

これを下部に書いている場合は削除しないとエラーが出た。

 

あとプログラムのファイル内のソースは書き換える必要がなかった。ここをいじらないと行けないなら面倒で途中で諦めてたと思う。

エラーが出た場合はGAEのダッシュボード上のログのところを見ると、「E」と表示があるから、左上に「+」の部分をクリックすると詳細が表示されて、あとはグーグルでそのエラーを検索するとすべて解決できた。以上30分位でできた。

小さな会社の Google Apps 導入・設定ガイド (Small Business Support)

コメントを残す