virtualenvを知ってから、ローカルでpython2とpython3を切り替えたりしながら作業してて楽しい。けれども、pythonのバージョン変えてherokuにdeployするというのをさっき初めてやってみて30分くらいかかったので、今後のためにメモしておく。
目的: python2で作っていたherokuアプリをpython3に変更する。
方法: アプリのルートに"runtime.txt"というファイルを置く。それだけ。中身は、
runtime.txt
python-3.4.2
と書くだけ。
で、はまってたのは一行目を空白で改行してたから!
エラー(一部抜粋)はこんな感じ。
remote: -----> Python app detected
remote: -----> Found runtime python-2.7.9, removing
remote: -----> Installing runtime (
remote: python-3.4.2)
remote: ! Requested runtime (
remote: python-3.4.2) is not available for this stack (cedar-14).
remote: ! Aborting. More info: https://devcenter.heroku.com/articles/python-support
remote:
remote: ! Push rejected, failed to compile Python app
バージョン指定を調べ直したり(https://devcenter.heroku.com/articles/python-runtimes)
して、それから空白行に気づいた。慣れないvimで書いてた。
あと、pythonのバージョン変えたらpip freeze > requirements.txt
をするのもわすれないこと。