Quantcast
Channel: FunWithLinux.net » Mike
Viewing all articles
Browse latest Browse all 38

CentOS 6 Google App Engine Python Development with Eclipse

$
0
0

With more and more companies moving applications to the cloud, Google App Engine makes a lot of sense.  GAE is a Platform as a Service (PaaS) product offered which runs on Google’s infrastructure.  Some of the touted capabilities are seamless, limitless, and completely automated application scaling.  In this article, you’ll learn how to setup a basic development environment for Google App Engine’s Python SDK on CentOS 6 using PyDev and Eclipse.




Unfortunately for us, the Repositories for CentOS 6 don’t include the latest Eclipse version or Python2.7, both of which are required to get your development environment up and running.  We’ll cover the installation of those items first.

Install Python2.7

First, we need to download, compile, and alternate install Python2.7.  Since CentOS 6 depends explicitly on Python2.6, we can’t just install overtop of the default install without breaking important packages (according to some sites on the web, I have not verified this).

In order to actually compile the package, we need the tools necessary to do so.  If you machine doesn’t already have it install, go ahead and install the “Development Tools” package group.

yum groupinstall “Development Tools”

Now that our development environment is setup, we can download, compile, and install Python2.7

wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz

tar zxvf <filename>

cd Python-2.7.6

./configure –prefix=/usr/local

(After configure runs, if you get any errors about missing compilers or other dependencies, now is the time you would install those packages.  There shouldn’t be anything missing, but I didn’t perform this on a new install of CentOS 6, so if it fails for  you, please post in the comments and I’ll see if I can add anything that might be missing to these steps.)

Run the next step as root so the compiled binaries can be installed.

make && make altinstall

Python 2.7 should now be installed at /usr/local/bin/python2.7

Install Eclipse

Eclipse is perhaps the world’s best IDE ever created.  It’s free, cross-platform, and has tons of extensions and plugins available.  My only complaint about Eclipse is that it’s a little RAM hungry, so if your primary workstation isn’t all that beefy, it may be a little sluggish, but should still be usable.

Before we install Eclipse, let’s get java7 installed, as it’s required by PyDev.

yum install java7

Eclipse comes as precompiled binaries, so we won’t have to configure anything special for this, and it just runs on CentOS 6.  The current version is Kepler, and can be download from here: Eclipse.org

There are various mirrors available at that site, choose one that works for you.

After downloading the file, simply untar it.

tar zxvf <filename>

The files will be extracted to a folder named eclipse.  cd into that directory, and we can run it with ./eclipse

Install PyDev

PyDev is a great project from Pydev.org.  It integrates your Python runtimes with Eclipse, and includes a number of great features.  If you’re developing in Python, it’s definitely worth looking into.

Start Eclipse, wait for it to load.  Now, we’re going to download PyDev, which integrates Python with Eclipse, as well as enables us to create Google App Engine projects.

Open the Install New Software Dialogue in Eclipse by selecting Help -> Install New Software

Eclipse install new software

At the top of the dialogue, select the Add button, and enter the name of the repo “PyDev” and the url: http://pydev.org/updates

Click “OK”.  After the repository is queried, you will be presented with two check boxes.  Check the top one, “Pydev”.  Click next and finish a few times, accept the license agreements, and accept any certificates if prompted (Make sure you check the box before clicking “OK” if you see this dialogue).

After install, choose to restart Eclipse.

Download Google App Engine SDK

We need to download the GAE Python SDK to allow us to actually build apps for GAE locally.  This SDK replicates the environment one can expect their apps to run on once uploaded to Google’s servers.

Download the GAE Python SDK:  wget http://googleappengine.googlecode.com/files/google_appengine_1.8.8.zip

Unzip the archive: unzip <filename>

Eclipse Configuration

Special thanks to this blog for this section:  http://www.mkyong.com/google-app-engine/google-app-engine-python-hello-world-example-using-eclipse/

Let’s setup our first project.

Select File -> New -> Project…

In the dialogue, expand PyDev and select PyDev Google App Engine Project

Give the project a name, we’ll use “webtest” in this example.

I highly recommend leaving the path for the project the default.  This will allow us to configure our variables easier in later steps.

You should see an error about an interpreter not being configured.  Click that blue link, and choose manual.  In the box provided, type in the full path of our python2.7 binary:  /usr/local/bin/python2.7

Click “Ok” to return to our project dialogue.  Next, select “Create ‘src’ folder and add it to PYTHONPATH” and select “Next”

On the following screen, browse to where we unzipped the Google App Engine files, and select that directory.  Leave all boxes checked in the popup, click okay, and click next.

Give the app any name you choose, you can edit this later if needed, in the first box.  In the second box, choose the “Hello Webapp World” project template, and click finish.

Your project should now be created.  Expand the project and the src folder, and open up helloworld.py.  If you try to run this file now, it will fail.  We need to setup our run configuration for this project.  Unfortunately, we’ll have to perform this step for each project we wish to create.

Select Run -> Run Configurations…

Highlight PyDev Google App Run in the left bar, and click the “new” button above that area.

runconfig

Name the new configuration something appropriate.  I suggest the project name for simplicity’s sake.  Browse for your project or just type it in.  Next, type in the full path name for the GAE dev server: /home/myuser/Downloads/google_appengine/dev_appserver.py  This will be where ever you unzipped it.  In my case, I just extracted the archive right in the Downloads folder.  This might not be an appropriate location if you are setting up your machine for multiple users.

runconfig2

Next, click the arguments tab at the top.  In the first box, paste  ${workspace_loc}${project_path}/src

Alternatively, you can type the full path to your project, including /src at the end.  This format will allow you to copy and edit the config easier if you choose to develop another app.

Hit apply near the bottom of the dialogue.  You should now be able to press the run button, visit the url http://localhost:8080 to view your project.

 

That should be it.  Your should be able to develop code for running on Google App Engine right on your local workstation.  Please post any comments or questions, thanks for reading!


Viewing all articles
Browse latest Browse all 38

Trending Articles