How to install libraries on Google App Engine for Python3

481 Views Asked by At

I have a Python3 project currently hosted on GCloud. I'm looking to enhance this project by allowing report generation based on a template. I'm investigating WeasyPrint.

The thing about WeasyPrint is that it has a lot of requirements required to manually install that can't be done through pip. One particular one is GDK-PixBuf, which not only require a sudo-install (?), but also references to PATH in the environment variable.

I'm a relative newbie to GCloud deployment and I'm not sure how to do this in the GCloud server, hence my (initial) reluctance to use WeasyPrint.

On top of that, while reading on on how to do this, Google themselves only has documentation for it in Python2 which says it(and Cairo) are not supported, nothing about Python 3, which is further confusing me.

The Python3 documentation itself is not helping much.

I found something with regards to this, but aside from its age, it's more catered towards Python2.

2

There are 2 best solutions below

0
On

App Engine standard does not let you install additional software beyond things pip can do for you, so I don't think it can meet your needs. App Engine flexible does allow that, but I think Cloud Run would be a better fit and easier to learn and use. Cloud Run has you specify a container that it then builds, deploys, and manages in response to web requests. You can install the needed binaries and set the PATH when the container is built.

See the Cloud Run quickstart for Python for an example Dockerfile that shows how to set environment variables and run Linux commands (such as installing needed software) during build time.

0
On

You won't be able to use WeasyPrint in GAE standard as it is dependent on some C-based packages (e.g. cairo, Pango, GDK-PixBuf), which the GAE's Python runtime is lacking - link.

However, you could use the GAE flexible environment as it allows using custom runtimes. In GAE flexible you can install the required components through the Dockerfile. Please see the example I wrote some time ago on this topic.