Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 423
Brian Hamill Avatar asked Mar 24 '18 20:03

Brian Hamill


2 Answers

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

enter image description here

like image 171
akhilmurali Avatar answered Sep 18 '22 20:09

akhilmurali


New Aptfile and requirements.txt attributes works for me:

in Aptfile

libsm6
libxrender1
libfontconfig1
libice6

in requirements.txt

opencv-python-headless==4.2.0.32

Remember to have the Buildpack included in settings.

https://github.com/heroku/heroku-buildpack-apt
like image 35
Zyncho Avatar answered Sep 18 '22 20:09

Zyncho