Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

python - How to use OpenCV with Heroku

When I attempt to deploy my application to Heroku I receive the following error:

File "/app/project/app/_ _init__.py", line 22, in <module>
File "/app/project/app/views.py", line 6, in <module>
import cv2
from .cv2 import *
File "/app/.heroku/python/lib/python3.6/site-packages/cv2/_ _init__.py", line 4, in <module>
2018-03-24T20:40:55.986945+00:00 app[web.1]: ImportError: libSM.so.6: cannot open shared object file: No such file or directory```

OpenCV is unable to find the libsm directory, however this application runs correctly locally. I have tried using a specific buildpack however those did not seem to find my site-packages folder.

How do I use openCV (python) on Heroku?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can install these missing libraries taking advantage of the heroku-buildpack-apt.

At the time of this writing, I have succesfully done it for this repo, hosted here, with the following steps:

  1. Add heroku-buildpack-apt to your buildpacks on Heroku platform
  2. Create a file named Aptfile and add the following libs:
libsm6
libxrender1
libfontconfig1
libice6

(one per line). Example here.

Edit: in newer versions of OpenCV, you need only to list python-opencv on the Aptfile, as seen in the docs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...