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
4

2 回答 2

5

这是一个依赖问题,我需要安装这个:

apt-get install libsm6 libxrender1 libfontconfig1

Ps:Heroku 的免费帐户不包括 ssh 连接,所以我切换到 Google Cloud Platform 并且它可以工作。

于 2017-10-07T15:04:57.593 回答
4

您必须安装一些依赖项,因为 Heroku 不会自动为您安装。

  1. 在您的项目目录中添加一个Aptfile并添加以下文件
  • libsm6

  • libxrender1

  • libfontconfig1

  • libice6

    注意:Aptfile 不应有任何 .txt 或任何其他扩展名。就像 Procfile

  1. 将编辑好的代码推送到 Github

  2. 在 heroku 仪表板中,
    转到您的应用程序 --> 设置 --> buildpacks --> 添加 buildpacks --> https://github.com/heroku/heroku-buildpack-apt.git
    复制并粘贴此链接 --> 添加构建包

  3. 部署您的应用

构建包添加

于 2021-01-07T05:20:25.897 回答