Joe Lennon

Rants, Raves & Recommendations

Archive for the ‘django’ tag

Using Pydev for Google App Engine development on a Mac

with 5 comments

I’ve been experimenting with Google App Engine a bit recently and although it’s not without its problems, it fits really well with a couple of small projects I’m working on at the moment. Up until now, I’ve been mainly working with TextMate and the Google App Engine launcher, which is fine, but hardly an ideal development environment. That’s where Aptana Pydev comes in.

Pydev is an Eclipse/Aptana plugin for developing Python applications. It has great support for Django and other Python frameworks, and is a great all-round Python development tool. The feature that caught my eye the most was built-in support for Google App Engine development, but I ran into a few problems when I tried to get up and running with it on my Mac. In this post, I will walk through how I got it all working in the end.

There are several options for downloading Pydev. Eclipse developers can download it as a plugin, or if you don’t use Eclipse, Pydev comes bundled in Aptana Studio (an Eclipse-based IDE that is geared towards Web development). In this post I will cover the Aptana method, but it should be simple to extract the relevant parts if you are going down the plugin path.

Head to the Aptana Studio 3 download page (product in beta at time of writing) and download the disk image to your Mac. When you mount this image and open it, you should see a Finder window like the one in Figure 1.

Figure 1. Aptana Studio disk image

Figure 1. Aptana Studio disk image

Follow the simple instructions and drag the Aptana Studio 3 folder into the Applications directory shortcut. This will install Aptana in your Applications directory. You will see the files being copied from the image as shown in Figure 2.

Figure 2. Copying files

Figure 2. Copying files

When this is completed, you can open the Aptana Studio 3 folder in your Applications directory and launch Aptana by opening the AptanaStudio3.app file, as seen in Figure 3.

Figure 3. Finding AptanaStudio3.app

Figure 3. Finding AptanaStudio3.app

When you first launch Aptana Studio, you will see a blank workspace, as shown in Figure 4.

Figure 4. Blank Aptana Studio Workspace

Figure 4. Blank Aptana Studio Workspace

Now it’s time for the fun stuff. First, you need to create a new project. Press [Cmd] + N to open the New Project wizard. In the list of Wizards, you should see a folder named “Pydev”. Expand this folder and you will find an option “Pydev Google App Engine Project”, as shown in Figure 5.

Figure 5. New Project Wizard

Figure 5. New Project Wizard

Make sure you’ve selected the correct option, and hit the Next > button to continue. On the next screen, you will need to enter details about the project, including the name of the project, the type of project (Python, Jython or Iron Python), the grammar version to use and the interpreter. Before you fill out this form, you’ll notice that there’s a link “Please configure an interpreter” in the related preferences before proceeding. This is shown in Figure 6.

Figure 6. PyDev Project Wizard

Figure 6. PyDev Project Wizard

Click on this link and the main Aptana Preferences window will open, and you will be brought straight to the “Interpreter – Python” page of the Pydev preferences section. On the right-hand-side, there’s a list (currently empty) of Python interpreters, with two enabled buttons to the right of the list, New and Auto Config, as can be seen in Figure 7.

Warning: Don’t use Auto Config, on my system it found Python 2.6, and for Google App Engine development you’ll want to use Python 2.5.

Figure 7. PyDev Python Interpreter Preferences

Figure 7. PyDev Python Interpreter Preferences

Click the “New” button and Aptana will open the Select interpreter dialog. Enter the following values into the relevant fields:

  • Interpreter Name: Python 2.5
  • Interpreter Executable: /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5

If you prefer, browse to the location of the executable and select it. The dialog should look like Figure 8.

Figure 8. Select interpretor

Figure 8. Select interpretor

Press the OK button to add this interpreter. Aptana will do some preparation, and before long you’ll be presented with another dialog that needs your attention. This one looks like the screen grab in Figure 9.

Figure 9. Adding folders to the SYSTEM pythonpath

Figure 9. Adding folders to the SYSTEM pythonpath

In my case I simply accepted the default selections and pressed OK, but if you need to, you can select the other options. When you press OK, you should be back in the Aptana Preferences window, which should now look more like Figure 10.

Figure 10. Updated PyDev Preferences

Figure 10. Updated PyDev Preferences

You can now close this screen by pressing OK in the bottom right of the window. After you do this, Aptana will go off and do some work, and you’ll see a window like the one shown in Figure 11. This might take a minute or two to complete so be patient.

Figure 12. Aptana background work

Figure 12. Aptana background work

When this progress window closes, you’ll be back at the Pydev Project setup screen. Enter whatever project name you like, I’ve called mine “game-planner” which is the same as the application ID for my Google App Engine application. Make sure “Python” is selected as the Project Type, and change the Grammar Version to 2.5. If you only set up the Python 2.5 interpreter, you can leave the Intepreter set to “Default”, or alternatively you can change this to “Python 2.5″ if you are unsure. The completed project screen should look something like Figure 13.

Figure 13. Project dialog, filled out

Figure 13. Project dialog, filled out

Press the Next > button to move on to the next step of the Project Wizard. This step asks you to select the Google App Engine Directory. It is shown in Figure 14.

Figure 14. Google App Engine Directory

Figure 14. Google App Engine Directory

You can use the Browse button, but unless you downloaded the zip archive of the App Engine Python SDK, you will not be able to find the directory in Finder. This is because the SDK package that comes in the form of the “Google App Engine Launcher” is wrapped up in a .app archive, which can’t be explored in Finder. See Figure 15 for an example of this.

Figure 15. Cannot browse GoogleAppEngineLauncher.app

Figure 15. Cannot browse GoogleAppEngineLauncher.app

The location it is looking for is the location where the Google App Engine files dev_appserver.py, appcfg.py, the lib directory and so on are located. If you are using the launcher version of the SDK, this is usually in the following location:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine

 

If you paste this into the Google App Engine Directory field, however, you’ll notice that it results in an error. This error is shown in Figure 16.

Figure 16. Error finding django lib directory

Figure 16. Error finding django lib directory

The reason for this error is relatively straightforward – Google App Engine doesn’t have a directory named django at that path. Apparently this issue will be fixed in the next release of Pydev. However, as seen in Figure 17, there are two other directories that are very similar, django_0_96 and django_1_2.

Figure 17. django directories that are available

Figure 17. django directories that are available

To solve the problem, we can simply create a symbolic link named django, which will point to the django_0_96 directory. To do this, open Terminal (Applications > Utilities > Terminal) and issue the following commands:

$ cd /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/
$ ln -s django_0_96 django

 

If you issue the ls command after doing this, you should see that there is now what looks like a django directory. This is a soft link to the django_0_96 directory, and if any changes are made in django_0_96, they will automatically be reflected in the django directory. Sample Terminal output is shown in Figure 18.

Figure 18. Mac OS X Terminal Output

Figure 18. Mac OS X Terminal Output

Next, go back to Aptana and enter the directory path again (cut it and re-paste it back) to refresh the wizard. This time, you should see a much friendlier result, like the one shown in Figure 19.

Figure 19. No errors this time around

Figure 19. No errors this time around

Click Finish and the project will be created. You might be asked to switch to the Pydev perspective, as shown in Figure 20. It’s up to you whether you do this, I personally checked the Remember my decision field and pressed the Yes button.

Figure 20. Pydev Perspective

Figure 20. Pydev Perspective

You should now be in your Pydev Google App Engine project. From here you can create, run and debug your Google App Engine applications. The default Pydev workspace is shown in Figure 21.

Figure 21. Pydev Eclipse Perspective

Figure 21. Pydev Eclipse Perspective

If you have any questions about this post, or have comments, suggestions or improvements, please leave a comment. Thanks for reading!

 

Written by Joe Lennon

March 25th, 2011 at 1:25 pm

Deploying Django

with one comment

In this IBM developerWorks article, I investigate the Django web development framework – an excellent MVC-style framework for building dynamic web applications in Python. I look at setting up a Django development environment, discuss the key components of a Django web application and then discover how a Django web application can be deployed to a production web server. The following is the abstract from IBM developerWorks:

Django is a Python-based open source Web application framework that focuses on making the process of creating database-driven Web sites and Web applications easier. Getting started with developing Django applications is simple, as a development Web server is included with the framework. However, this server is not suitable for use in a production environment, so further steps are required to deploy your Django application to the Web. In this article, you will learn about the Django framework and how to install it on your local machine. Discover how a Django application is made and about the automatic administration interface created for your application. You will then find out how to deploy your Django application to the Web on a server running Apache and mod_python. Finally, learn how Django applications can and should be scaled as your application’s requirements grow.

Read the article at http://www.ibm.com/developerworks/opensource/library/os-django/

Written by Joe Lennon

April 7th, 2009 at 11:08 am