Cant make opencv work on heroku
Asked Answered
G

2

6

I'm trying to make opencv work on Heroku but i have the following error on the server's log file :

2017-10-05T23:17:08.145096+00:00 heroku[web.1]: State changed from crashed to starting
2017-10-05T23:17:19.477843+00:00 heroku[web.1]: Starting process with command `python Main.py`
2017-10-05T23:17:23.469550+00:00 heroku[web.1]: State changed from starting to crashed
2017-10-05T23:17:23.458477+00:00 heroku[web.1]: Process exited with status 1
2017-10-05T23:17:23.268234+00:00 app[web.1]: Traceback (most recent call last):
2017-10-05T23:17:23.268249+00:00 app[web.1]:   File "Main.py", line 3, in <module>
2017-10-05T23:17:23.268434+00:00 app[web.1]:     from MostDominantColor import get_color
2017-10-05T23:17:23.268541+00:00 app[web.1]:   File "/app/utils.py", line 3, in <module>
2017-10-05T23:17:23.268435+00:00 app[web.1]:   File "/app/MostDominantColor.py", line 2, in <module>
2017-10-05T23:17:23.268538+00:00 app[web.1]:     import utils
2017-10-05T23:17:23.268648+00:00 app[web.1]:     import cv2
2017-10-05T23:17:23.268790+00:00 app[web.1]: ImportError: libSM.so.6: cannot open shared object file: No such file or directory
2017-10-05T23:17:23.268663+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/cv2/__init__.py", line 9, in <module>
2017-10-05T23:17:23.268776+00:00 app[web.1]:     from .cv2 import *

On line 9 of the __init__.py file there is a piece of code that is only useful for IDE's autocompletion :

8 # make IDE's (PyCharm) autocompletion happy
9 from .cv2 import *

I understand that this line is causing a problem when importing cv2 in my code, is there a way to delete the line from the server (knowing that cv2 library is downloaded by pip on the server side so i can't just push such an edit to Heroku via git)

Any suggestion is welcomed !

python : 3.6.2
opencv-python==3.3.0.10
Gestation answered 5/10, 2017 at 23:38 Comment(0)
G
5

It was a dependency problem, what i needed is to install this:

apt-get install libsm6 libxrender1 libfontconfig1

Ps: Heroku's Free account doesn't include ssh connexion so i switched to Google Cloud Platfom and it works.

Gestation answered 7/10, 2017 at 15:4 Comment(1)
For a solution on Heroku platflorm, see this answer: https://mcmap.net/q/888328/-how-to-use-opencv-with-herokuLicha
B
6

You have to install some dependencies, as Heroku will not automatically do it for you.

  1. Add an Aptfile in your project directory and add the below file
  • libsm6

  • libxrender1

  • libfontconfig1

  • libice6

    NOTE: Aptfile should not have any .txt or any other extension. Just like the Procfile

  1. Push the edited code to Github

  2. In heroku dashboard,
    goto your-app --> settings --> buildpacks --> add buildpacks --> https://github.com/heroku/heroku-buildpack-apt.git
    copy and paste this link --> add buildpack

  3. Deploy your app

buildpack adding

Busoni answered 7/1, 2021 at 5:20 Comment(0)
G
5

It was a dependency problem, what i needed is to install this:

apt-get install libsm6 libxrender1 libfontconfig1

Ps: Heroku's Free account doesn't include ssh connexion so i switched to Google Cloud Platfom and it works.

Gestation answered 7/10, 2017 at 15:4 Comment(1)
For a solution on Heroku platflorm, see this answer: https://mcmap.net/q/888328/-how-to-use-opencv-with-herokuLicha

© 2022 - 2024 — McMap. All rights reserved.