To try this Python example in the App Engine Flex environment, for the context of this tutorial, it would be convenient to use Cloud Shell.:
- Once you have git installed, clone the following directory:
git clone https://github.com/GoogleCloudPlatform/python-docs-samples
- Now, Python sample codes can be found in the following sub-directory:
cd python-docs-samples/appengine/flexible/hello_world
- Now, run the application with the following:
python main.py
- You can also view the output on your browser's localhost:
http://localhost:8080
- From this directory, we can run Python code. But before that, if you don't have virtual environment installed, do it with the following command:
sudo pip install virtualenv
- In this virtual environment, create a dedicated Python environment along with its dependencies:
virtualenv env
source env/bin/activate
pip install -r requirements.txt
- Now, we can deploy this app by running the following command in the hello world directory:
gcloud app deploy
- Of course, the gcloud command only works if you have Google Cloud SDK installed on your local machine. We can view the deployed app's result with the following command. It will open a browser window and the address bar will contain an address having an http//PROJECT_ID.appspot.com pattern:
gcloud app browse