LoginSignup
8
5

More than 5 years have passed since last update.

python37版のgoogle app engineを動かすのにとても手間取ったお話

Last updated at Posted at 2018-09-13

結論から言うと、python27とpython37の両方が動かせないと、開発できなかった:frowning2:

python37 beta!!

という訳でgaeにbeta版ではありますがpython37のruntimeがgaeに追加されました。
python2.7の寿命のことを考えると非常にありがたいですので、早速使ってみました。

python37のinstall

$ pyenv install 3.7.0
$ pyenv global 3.7.0

とまぁ、こんな感じでルンルン気分で3.7.0をインストールして、2.7から切り替えてみました:laughing:

動かないdev_appserver.py

3.7版の簡単なhello worldも書けた、さぁデバッグだ!
参考

$ dev_appserver.py .

ERROR: Python 3 and later is not compatible with the Google Cloud SDK. Please use Python version 2.7.x.

If you have a compatible Python interpreter installed, you can use it by setting
the CLOUDSDK_PYTHON environment variable to point to it.

Google Cloud SDKがpython3.7.0に対応していない……だと……:dizzy_face:

動かし方

つまり、python37でgaeをlocalにて開発するのにあたって……

  • dev_appserver.pyはpython2.7.xで動かす必要がある
  • python37版のソース自体はpython3.7.0で動かす必要がある

ということでした:kissing_heart:

なので、dev_appserver.pyを直接実行するのではなく、python2.7の引数に渡してあげる形にしてあげます。

$ python --version
Python 3.7.0
$ CLOUDSDK_PYTHON=~/.pyenv/versions/2.7.12/bin/python
$ $CLOUDSDK_PYTHON /hogehoge/dev_appserver.py .

動いた:stuck_out_tongue_closed_eyes:
毎回この手のを設定するのもめんどくさいので、aliasを切って確実に2.7.12で動くようにするのも有りかも!

Pycharmでpython37版のgaeを動かしたい!

うん、サポートしていないんだ、それは:alien:

python27で全てを動かすか、37でプロジェクトを動かすかの2択しか取れない……!
が、27にするとpython37のruntimeは動かせないし、37にするとdev_appserver.pyが動かない!

起動はもちろんデバッグもできない……! 不便!!!
早く正式対応して欲しいところ:thinking:

8
5
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5