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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

For a solution on Heroku platflorm, see this answer: stackoverflow.com/a/51004957/660711

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.