HerokuにTalibがインストールできない
結論からいくとtalibの関数を使用したpyファイルをHerokuにデプロイするときはtalibはrequirements.txtには書いてはいけない。書くとPUSH時に自動でインストールしようとするが、以下のようなエラーを吐く。
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-c7nsf1wo
remote: cwd: /tmp/pip-install-4lr_bjtl/TA-Lib/
remote: Complete output (5 lines):
remote: Traceback (most recent call last):
remote: File "", line 1, in
remote: File "/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py", line 62, in
remote: import numpy
remote: ModuleNotFoundError: No module named 'numpy'
remote: ----------------------------------------
remote: ERROR: Failed building wheel for TA-Lib
remote: Running setup.py clean for TA-Lib
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' clean --all
remote: cwd: /tmp/pip-install-4lr_bjtl/TA-Lib
remote: Complete output (5 lines):
remote: Traceback (most recent call last):
remote: File "", line 1, in
remote: File "/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py", line 62, in
remote: import numpy
remote: ModuleNotFoundError: No module named 'numpy'
remote: ----------------------------------------
remote: ERROR: Failed cleaning build dir for TA-Lib
remote: Failed to build TA-Lib
remote: Installing collected packages: chardet, certifi, urllib3, idna, requests, six, python-dateutil, numpy, pytz, pandas, TA-Lib
remote: Running setup.py install for TA-Lib: started
remote: Running setup.py install for TA-Lib: finished with status 'error'
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-z8xkn_n8/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.6m/TA-Lib
remote: cwd: /tmp/pip-install-4lr_bjtl/TA-Lib/
remote: Complete output (27 lines):
remote: /tmp/pip-install-4lr_bjtl/TA-Lib/setup.py:79: UserWarning: Cannot find ta-lib library, installation may fail.
remote: warnings.warn('Cannot find ta-lib library, installation may fail.')
remote: running install
remote: running build
remote: running build_py
remote: creating build
remote: creating build/lib.linux-x86_64-3.6
remote: creating build/lib.linux-x86_64-3.6/talib
remote: copying talib/test_stream.py -> build/lib.linux-x86_64-3.6/talib
remote: copying talib/deprecated.py -> build/lib.linux-x86_64-3.6/talib
remote: copying talib/test_abstract.py -> build/lib.linux-x86_64-3.6/talib
remote: copying talib/test_func.py -> build/lib.linux-x86_64-3.6/talib
remote: copying talib/abstract.py -> build/lib.linux-x86_64-3.6/talib
remote: copying talib/__init__.py -> build/lib.linux-x86_64-3.6/talib
remote: copying talib/test_pandas.py -> build/lib.linux-x86_64-3.6/talib
remote: copying talib/test_data.py -> build/lib.linux-x86_64-3.6/talib
remote: copying talib/stream.py -> build/lib.linux-x86_64-3.6/talib
remote: running build_ext
remote: building 'talib._ta_lib' extension
remote: creating build/temp.linux-x86_64-3.6
remote: creating build/temp.linux-x86_64-3.6/talib
remote: gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/app/.heroku/python/lib/python3.6/site-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/app/.heroku/python/include/python3.6m -c talib/_ta_lib.c -o build/temp.linux-x86_64-3.6/talib/_ta_lib.o
remote: talib/_ta_lib.c:526:10: fatal error: ta-lib/ta_defs.h: No such file or directory
remote: #include "ta-lib/ta_defs.h"
remote: ^~~~~~~~~~~~~~~~~~
remote: compilation terminated.
remote: error: command 'gcc' failed with exit status 1
remote: ----------------------------------------
remote: ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4lr_bjtl/TA-Lib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-z8xkn_n8/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.6m/TA-Lib Check the logs for full command output.
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to <プロジェクト名>.
numpyが無いと言っているみたいだが、直前にNumpyをインストールしているので、なんでNumpyを見ないのか謎である。とりあえずrequirements.txtには書かず下記に記載しているコマンドを実行してTalibは別にインストールするのが推奨らしい
Heroku PythonTA-Libパッケージを使用する
このビルドパックは、公式のHerokuPythonビルドパックと組み合わせて使用する必要があります。
$ heroku buildpacks:add --index 1 heroku/python $ heroku buildpacks:add --index 2 numrut/ta-lib
numrut/ta-libbuildpack HerokuのBuildpackレジストリはbuildpackの最新の安定版が含まれています。このGithubリポジトリの最新のビルドパックコードを使用する場合は、ビルドパックをGithubURLに設定できます。
$ heroku buildpacks:add --index 2 https://github.com/numrut/heroku-buildpack-python-talib
これでHerokuでもTalibの関数が動くと思います。talibは便利なんですけど、裏でC++かなんかが動いているせいで新規環境へのインストールでハマりやすのがネックですね。これだけで使うのに若干躊躇してしまいます。処理速度はちょっと遅くてもいいので普通にpipだけでインストールできるテクニカル計算ライブラリが欲しいところです。
参照:https://elements.heroku.com/buildpacks/numrut/heroku-buildpack-python-talib


コメント