0

I have a simple application that I'd like to deploy to a GAE standard or flexible environment, and it requires the generation of simple audio files.

I have code that runs well locally (on the dev server) using PySoundfile, but I run into errors with the underlying libsndfile when the application is deployed.

Traceback (most recent call last):
  File "/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
    worker.init_process()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/env/local/lib/python2.7/site-packages/gunicorn/util.py", line 352, in import_app
    __import__(module)
  File "/home/vmagent/app/main.py", line 3, in <module>
    import tonegen
  File "/home/vmagent/app/tonegen.py", line 4, in <module>
    import soundfile as sf
  File "/env/local/lib/python2.7/site-packages/soundfile.py", line 267, in <module>
    _snd = _ffi.dlopen('sndfile')
  File "/env/local/lib/python2.7/site-packages/cffi/api.py", line 141, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/env/local/lib/python2.7/site-packages/cffi/api.py", line 802, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/env/local/lib/python2.7/site-packages/cffi/api.py", line 797, in _load_backend_lib
    raise OSError(msg)
OSError: ctypes.util.find_library() did not manage to locate a library called 'sndfile'

I've also tried wave unsuccessfully.

Jeremy Gordon
  • 551
  • 4
  • 15

1 Answers1

1

In the flexible environment you could try to build and use a custom runtime in which you can add non-python dependencies, like OS libraries (libsndfile in your case and whatever else you may need).

Basically the same answer as in How oracle jdk can be configured in Google App Engine Flexible environment.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • On this page it says that custom runtimes dont support the GAE APIs: https://cloud.google.com/appengine/docs/flexible/python/customizing-the-python-runtime Does this mean that if we use this approach we can't use the GCP datastore? – Jeremy Gordon Feb 08 '19 at 01:08
  • I *think* it means you can't use the `ndb` client library (true for the non-custom flex apps too). But the datastore can be used (with the generic client library) from any python app, even from outside the google cloud, see https://stackoverflow.com/a/49124207/4495081. – Dan Cornilescu Feb 08 '19 at 03:09
  • 1
    This worked. Used GAE flex + a custom python runtime based on gcr.io/google-appengine/python which allowed use of the datastore, flask, as well as installation of the needed libs. – Jeremy Gordon Feb 08 '19 at 17:28