Tjorriemorrie
Tjorriemorrie

Reputation: 17282

How to import Flask into appengine

Getting the lovely error:

ERROR    2015-09-23 13:14:12,500 cgi.py:122] Traceback (most recent call last):
  File "public/run.py", line 2, in <module>
    from src import app
  File "public/src/__init__.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask

I've installed flask into public/lib with pip install -t lib -r requirements.txt.

public/appengine_config.py

from google.appengine.ext import vendor

# Add any libraries installed in the "lib" folder
vendor.add('lib')

# also does not work
# import os
# vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))

public/app.yaml

version: 1
runtime: python27
api_version: 1
threadsafe: false

handlers:
- url: /static
  static_dir: src/static

- url: /
  script: run.py

public/run.py

from google.appengine.ext.webapp.util import run_wsgi_app
from src import app

run_wsgi_app(app)

public/src/__init__.py

from flask import Flask
# import settings

app = Flask('app')
# app.config.from_object('src.settings')

import views

Upvotes: 3

Views: 194

Answers (2)

David Stack
David Stack

Reputation: 129

You might also want to check out the gae-init project as it uses Flask and is built on GAE. I found it's a great way to get up and running quickly.

Upvotes: 2

Josh J
Josh J

Reputation: 6893

Take a look at the Starter Project. More importantly, you should change your app.yaml to point to the the flask wsgi app.

- url: .*
  script: src.app

The run.py script and run_wsgi_app() is the old way to run your app and should not be used.

Upvotes: 2

Related Questions