I'm trying to do a relative import in App Engine using python. Here is my basic situation:
app/
models.py
app.yaml
/mymodule/
test.py
mymodule.yaml
I'm trying to import models.py.. basically I have the same datastore models that are being using across different modules, so I was hoping to be able to import models.py from within test.py (or any other module).
How do relative imports work with App Engine? Thanks.
Edit: My app.yaml file:
application: [my app name]
version: main
runtime: python27
api_version: 1
threadsafe: true
inbound_services:
- mail
builtins:
- appstats: on
handlers:
[my handlers]
libraries:
- name: webapp2
version: "2.5.1"
- name: jinja2
version: latest
- name: markupsafe
version: latest
- name: ssl
version: latest
I believe the solution is to put the
mymodule.yaml
under app. It seems that the root of your code in thePYTHONPATH
is the directory where your module'syaml
file is.Create one empty file under
app
called__init__.py
to transform your directory into a package and then you will be able to import like:And you might want to add the same file into your
mymodule
directory as well.