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?
No, It doesn't. Google App Engine (GAE) uses sandboxed Python 2.7 runtime for Python applications. That is the normal App Engine Hosting. However, in GAE you can use Managed VM Hosting.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With