If you can't get Google Cloud SDK to run on your computer, you can still use the webapp2 Python framework without the Cloud SDK. This is a step-by-step tutorial on how to do it.
Open PyCharm and click on Create New Project.
In the next step define the project path and optionally create a virtual environment.
Now that you've started a new project, open the Terminal tab (below) and install three PIP libraries with the following commands:
pip install WebOb
pip install Paste
pip install webapp2
webapp2
is the Python framework we'll use and it needs WebOb
in order to work correctly. Paste
is a HTTP server that we'll use to run our website on our computer.
Create a file called main.py
in the root of your project.
Then add the following code in it:
import webapp2
# handlers
class MainHandler(webapp2.RequestHandler):
def get(self):
return self.response.write('Hello, SmartNinja!')
# URLs
app = webapp2.WSGIApplication([
webapp2.Route('/', MainHandler),
], debug=True)
# run the localhost server
localhost = True # change to False before deploying to Google Cloud (GAE)
if localhost:
def main():
from paste import httpserver
httpserver.serve(app, host='localhost', port='8080')
if __name__ == '__main__':
main()
Now you can finally run your new web app! Right-click on main.py
and select Run 'main'.
A new window will open in your PyCharm below. Click on the http://localhost:8080 link and your web app will open in the browser.
Change "Hello, SmartNinja!" into something else, for example "Hello, Your Name!". When you do this change, you'll have
to reload both main.py
and your browser to see the changes.
Click on the green curved arrow to reload main.py
:
That's it! You've successfully set up a localhost web app. :)
Even if the Cloud SDK does not work on your computer, you can still deploy this web app on Google Cloud (on Google App Engine). See this tutorial to learn how: click here.