LoginSignup
23
14

More than 5 years have passed since last update.

herokuでOpenCVを利用する [Python3]

Last updated at Posted at 2019-02-02

はじめに

requirement.txtにopencv-pythonを加えて, デプロイすると以下のようなlogが…

2019-02-01T09:13:56.472857+00:00 app[web.1]: import cv2
2019-02-01T09:13:56.472859+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/cv2/__init__.py", line 3, in <module>
2019-02-01T09:13:56.472861+00:00 app[web.1]: from .cv2 import *
2019-02-01T09:13:56.472874+00:00 app[web.1]: ImportError: libSM.so.6: cannot open shared object file: No such file or directory

入らない…

結論

libSM.so.6がないようなので, 入れるために以下の手順を踏んでいきます.
1. buildpacksにhttps://github.com/heroku/heroku-buildpack-apt を追加
2. Aptfileをプロジェクトフォルダに追加

以下に詳細を書いていきます.

1. buildpacksへ追記

自分の知る限り, 以下の二つの方法のどちらでも追加できます.

Herokuのページから追加する

Herokuのページのsettings>buildpacksで https://github.com/heroku/heroku-buildpack-apt を追加する.

terminalから追加する

以下のコマンドをたたきます.

$ heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt

2. Aptfileをプロジェクトフォルダに追加

requirements.txtやProcfileなどがある階層に以下のAptfileを追加します.

Aptfile
libsm6
libxrender1
libfontconfig1
libice6

以上です!

23
14
6

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
23
14