1
votes

My project structure looks like below,

.
├── app
│   ├── api
│   ├── models
│   ├── services
│   │   └── lib
|   |   |__ worker.yaml
|   |   |__ worker.py
|   |_ main.py
|_ app.yaml

I'm trying to import models from app module (ie, default module) in worker.py like,

from app.models import db

But it shows No module named app.models. But I can achieve the same inside main.py.Note that I'm running both app.yaml and worker.yaml files.

1

1 Answers

5
votes

When deployed, GAE Services/modules do not share anything outside their module directory, which is the directory in which their .yaml file exists.

So worker.py won't see anything above the services dir (where worker.yaml exists), thus it can't see models. But main.py can, since models is inside its app dir (where app.yaml exists).

You could symlink models inside services if you want, see Sharing entities between App Engine modules

Or maybe take a look at Can a default service/module in a Google App Engine app be a sibling of a non-default one in terms of folder structure? for an example of how I'd structure a multi-module app?