AaronDT
AaronDT

Reputation: 4060

Google app engine deploy flask app - ImportError: libSM.so.6: cannot open shared object file: No such file or directory

I am trying to deploy a python flask app to google cloud. Once the app starts running I get the following error:

  File "/home/vmagent/app/app.py", line 11, in <module>
    import cv2
  File "/env/lib/python3.4/site-packages/cv2/__init__.py", line 9, in <module>
    from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or directory

Doing some research on the problem, I figured out that this seems to be a problem related to opencv-python and the following line should fixes the issue on linux:

sudo apt-get install libsm6

However, since I am using Mac I am unable to use apt-get to install libsm6 locally and since I am deploying using a requirements.txt file which does not accept apt-get I am stuck fixing this. I tried to SSH into the running instance on google cloud, however it does not accept apt-get install libsm6 either, telling me I lack admin rights:

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

changing directory to root didn't help either. Does anyone know how to fix this?

I have also tried python version 3.5 and 3.4 with no luck.

Upvotes: 2

Views: 1796

Answers (2)

ciacicode
ciacicode

Reputation: 708

From this info I assume you are not using a virtual environment. If Google Cloud gives you this error is because the python package you are referencing is not installed in /lib of your project. If you follow this Getting started guide you will notice that it advises first of creating a virtual env and then using the requirements.txt file to basically replicate that exact environment on Google Apps, hence the

pip install -t lib -r requirements.txt

My advise is to follow closely the getting started AND the github example and notice differences in terms of pip install in lib folder.

Update: Looking more closely at the stack trace the problem seems to originate from cv2 library depending on libSM.so.6 which is a C library. Google App Engine is very picky with regards to C libraries in python projects.

Suggestion is to try to use an alternative library for whatever cv2 does, a library that is pure Python.

Upvotes: 2

Dan Cornilescu
Dan Cornilescu

Reputation: 39824

Since you're using the flexible environment you can create a custom runtime based on the corresponding google-supplied docker image in which you add the additional dependencies your app require. From About Custom Runtimes:

Custom runtimes allow you to define new runtime environments, which might include additional components like language interpreters or application servers.

See also Building Custom Runtimes.

Upvotes: 2

Related Questions