5

I'm trying to figure out how to add a internal package to a Google App Engine deployment with Python 3 (standard).

For Python 2 the way to package modules was using a local lib/ folder and appengine_config.py. This seems not to work anymore for Python 3? At least my app cannot find modules which are in the lib/ folder.

For Python 3 it's possible to just pip3 install -t . the package. But this gets really messy as all packages are just installed in the app root and will also be added to the git repository of our app.

We cannot use requirements.txt as the module is internal and will not be available on PyPI.

Is there another way to package modules for Google App Engine using Python 3?

Dustin Ingram
  • 15,737
  • 2
  • 40
  • 56
Carsten Rietz
  • 401
  • 2
  • 10
  • Try placing the package's directory right under the top level service directory rather than under `lib`, side-by-side with with the `app.yaml` file. From GAE's perspective this *should* appear just like another package of your app code. Not sure if just symlinking the directory from somewhere else would work like in the 1st generation (python 2.7) standard environment (see https://stackoverflow.com/a/34291789/4495081) to avoid copying the package – Dan Cornilescu Nov 19 '18 at 18:12

1 Answers1

4

The Python 3.7 Standard runtime is an "idiomatic" Python runtime, which means it doesn't automatically add the special lib directory to the search path for modules.

You should continue "vendoring" your private modules into a lib directory, but you'll need to make a change to how you import them.

If your private package is foobar, and you've done pip install -t lib foobar, then in your project, instead of:

import foobar

you do:

import lib.foobar

(You'll also need to add an empty __init__.py file to your lib directory, to make it a module.)

Dustin Ingram
  • 15,737
  • 2
  • 40
  • 56