Azure FunctionsでPythonを使うメモ(LinuxイメージのFunction追加&pyodbc&fbprophet編)
(2019/1/23訂正)
LinuxイメージのAzure FunctionsへのFunction追加ですが、基本はバイナリ依存するようなモジュールはすんなり追加できません。
それでも、pyodbcだと「--build-native-deps --no-bundler」だけでいけたのですが、fbprophetに結構苦戦して、できたりできなかったりしていたのですが・・・。
結論:fbprophetのビルドには大量にメモリを使うので・・、docker for windows上でやるときはメモリをたくさん割り当てる必要がある
作業は、WSL(Ubuntu)+docker for windows(Windows 10 pro)で実行したのですが、docker for windowsで作業する場合、VMに割り当てるメモリを設定できます。1時期4GBにしたことがあったのですが、基本は2GBでやってました。が、これがいけなかった。
2GBだとビルドも時間がかかり、挙句の果てにはエラー。4GBは割り当てましょう!
ちなみにfbprophetは、Facebook社開発の予測ライブラリです。
facebook.github.io
xxxxxx$ python -m venv venv xxxxxx$ source venv/bin/activate (venv) xxxxxx$ func init Select a worker runtime: 1. dotnet 2. node 3. python Choose option: 3 python Installing wheel package Installing azure-functions==1.0.0a5 package Installing azure-functions-worker==1.0.0a6 package Running pip freeze (venv) xxxxxx$ func --version 2.3.148 (venv) xxxxxx$ pip install pyodbc (venv) xxxxxx$ pip install fbprophet (venv) xxxxxx$ pip install scipy (venv) xxxxxx$ pip install statsmodels (venv) xxxxxx$ pip freeze > requirements.txt (venv) xxxxxx$ vi requirements.txt (※「pkg-resources==0.0.0」を削除) (venv) xxxxxx$ func host start (※ローカルでの稼働を確認) %%%%%% %%%%%% @ %%%%%% @ @@ %%%%%% @@ @@@ %%%%%%%%%%% @@@ @@ %%%%%%%%%% @@ @@ %%%% @@ @@ %%% @@ @@ %% @@ %% % : : : (venv) xxxxxx$ func azure functionapp publish MyXxxxxxFunc --build-native-deps --no-bundler Getting site publishing info... Running 'docker pull mcr.microsoft.com/azure-functions/python:2.0'...done Running 'docker run --rm -d mcr.microsoft.com/azure-functions/python:2.0'....done : : : (venv) xxxxxx$