1
votes

According to the getting started doc and the built-in third-party libraries. You should be able to add flask to your project using libraries in your app.yaml.

Although Flask is bundled into the runtime, and could be used simply by adding in the app.yaml file's libraries: directive, this tutorial puts a copy of the library in your the app's directory, which demonstrates how you would include an unbundled third-party library so that your app can use it.

app.yaml

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: main.app

libraries:
- name: flask
  version: "latest"

main.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

However, I keep getting:

ImportError: No module named flask

Has anyone been able to get this to work? Is there something I'm missing? I'm using the Cloud SDK for local development on Linux.

1
FWIW, your example works just fine for me - linux GAE SDK 1.9.61. Just one note: the indentation of your app.yaml file is not displayed OK - I'll edit your post to correct that - check if the actual indentation in the file is ok or not as it might have something to do with the error.Dan Cornilescu
The website makes it seem that the GAE SDK is more legacy for people needing 'appcfg' command. If I have to use that it would defeat my purpose I can also use the third party method that is not for built-in libraries, but neither one is ideal. I'd like to use the recommended software with built-in library that the docs indicate should work.George Bittmann
That's debatable - I'm still happier with it than with the cloud SDK. Regardless - the cloud SDK is theoretically packing the same core as the individual GAE SDK(s) inside their respective language components - they even use the same version #s). But yes, occasionally there are divergences in functionality which can be addressed by switching between SDKs - which is why I have both installed :) Older, but still applicable in some regards: stackoverflow.com/questions/33769879/…Dan Cornilescu
It sounds like you have the Cloud SDK installed, if you run gcloud components install app-engine-python does the module not found error go away? (assuming you haven't mapped a local lib folder)BrettJ
sudo apt-get install google-cloud-sdk-app-engine-python yields sudo apt-get install google-cloud-sdk-app-engine-pythonGeorge Bittmann

1 Answers

0
votes

You must also install in the lib folder in your project root:

pip install flask -t lib/

I guarantee you this will work