1

I have simple Python app I'm trying to deploy to App Engine. The app runs perfectly in my local environment. I've been struggling for hours with absolute and relative paths. I have the following simple filter in the /utils folder, filters.py file:

from .. import app

@app.template_filter()
def nicedate(datestring):
    datestring=datestring[:10]
    return datestring

When running my app, I get the following error:

from .. import app
ValueError: attempted relative import beyond top-level package

That's strange, because I understand the . means "one level up" and I have the following project structure:

main.py
views.py
requirements.txt
app.yaml
  util/
   filters.py
  templates/
  static/

etc.

And the relative import with two dots works perfectly in my development environment.

So, filters.py are just one level down, and the .. is supposed to take me one level up.

However when I use only one dot, I get:

from . import app
ImportError: cannot import name 'app'

How should I do this import?

  • Possible duplicate of [How to do relative imports in Python?](https://stackoverflow.com/questions/72852/how-to-do-relative-imports-in-python) – Oddmar Dam Jun 14 '19 at 05:31
  • 1
    @OddmarDam Obviously this is NOT a duplicate question. It's a new and specific question about GAE environment, not about python relative paths in general. – Clement Bjelland Jun 14 '19 at 05:42
  • have you tried to create one an __init__.py file to transform your directory into a package.... have a look at this question https://stackoverflow.com/questions/23898367/how-to-do-relative-imports-on-app-engine-python – Paddy Popeye Jun 14 '19 at 08:22
  • Do you have `__init__.py` file on the folder `utils`? It is required for this situation. – Luiz Ferraz Jun 17 '19 at 16:55
  • Thanks @LuizFerraz, I will try that – Clement Bjelland Jun 18 '19 at 18:29

0 Answers0