Using Monty Karel in Eclipse

This page describes how to get Monty Karel running in Eclipse. Note that it was built in Eclipse.

First note that Python, the language of Monty Karel, has two incompatible versions: 2.x and 3.x. We assume you will be using Python 3.x, currently 3.4. The book, except early copies, is Version 3 compatible. The differences are minor, but enough that you want to choose.

Background

Eclipse is written in Java and often used for Java development, but it is actually a plug-in platform that can be used for many purposes; even non programming. In order to use it for Python, you need a plug-in and the plug in has prerequisites.

Eclipse uses the concept of a Workspace. You have one workspace open at a time. The look of the workspace depends on its Perspective. There is a Java perspective and a PyDev perspective, for example. The perspective governs the placement of frames within the main window, though each perspective can be tailored. The left-most frame generally contains a list of Projects and each project manages a set of files used to build an application or set of related applications. For use with Monty Karel you will need one workspace and one project to contain all your files along with the files supplied with the book. The files are arranged in folders.

The central window of the workspace is for editing and the PyDev perspective provides an Python editor to ease your work. There are other windows/frames, such as the Console to view printed output and provide inputs to programs.

Many Eclipse functions are available with a right mouse click. For example, to create a new file, right click on a folder in the leftmost pane and select New -> Pydev Module. A dialog will then let you give it a name.

There are many icons (actually buttons) in the workspace boundary. They all have tool-tips, so floating the mouse over an icon gives you an idea of what it does.

Installation

This is a one time process, but quite involved. You should read the following before you start to get an idea of what is involved and then treat it as a checklist.

1. Make sure you have Java v. 1.7 installed in your machine. (Not a later version - 1.7) You need at least the JRE but may as well download the JDK as well. If you don't know what version you have, open a command window in your system and type

java -version

My system (a Macintosh) responds with:

java version "1.7.0_71" (etc)

Java 1.7 is an explicit requirement for the plugin we install later. If you need Java, get it from javasoft.com which redirects to Oracle. You want the Java SE, not a more elaborate or limited one. Download and install it. Then ask your system again for its version and be sure it is there.

2. Install Python V3. Go to python.org and, under the Downloads tab select Python V3 (currently 3.4.2.). Download and install it. You might also have python v2 installed as well and that is OK.

3. Download a recent version of Eclipse from eclipse.org. If you have an older version, it may not work. As I write this, the current version on the Mac is 4.4.1 (Eclipse Luna). Install and run it.

Whenever you run Eclipse, you get asked to specify a workspace and it suggests one called Workspace. I would, instead, use Browse to create a new folder in your Documents and name it something like KarelPython to use as the workspace. This will then become the default. A workspace is, among other things, a folder, but it has hidden files so let Eclipse create it.

After you open it for the first time, you get a splash page that gives you access to tutorials, etc. You can explore here for a bit, but eventually you want the WorkBench button in the upper right corner. Press this to see the workspace with many panes. The left pane is for projects and their files. The center pane is to edit.

4. Install the PyDev plugin into Eclipse. Go to pydev.org and click Download to get a page (written for geeks) that explains what is needed, including the above. There is special information for Mac users that may be needed to get Java 1.7 properly recognized. We won't actually need to go through all of the detail there, but it is good to know where it is.

With Eclipse open Choose Help->Install New Software. In the resulting dialog box, paste the URL: http://pydev.org/updates and then click Add. In that dialog give it a name, like PyDev and if necessary, paste the URL again in the second text box (location) and press OK. Now, in the central dialog window select PyDev (but not the other) and then Next, etc until the software installs, which will take a while, as it needs to download. You may get asked for confirmation once or twice. Select OK for each of these after reading what is being asked and making appropriate selections.

5. Install the Monty Karel software. Download the Monty V3 software from my downloads page. It is a zip file, but you need not unzip it. Instead, back in Eclipse, select Import from the File menu. Under General in the dialog select Existing Projects Into Workspace and click Next. Navigate to the zip file and choose it. A project will be created in the left pane.

Next, in the Windows Menu of Eclipse, select Open Perspective -> Other and select the Pydev perspective. The window layout will change for python (rather than Java) development.

Now you can try to run a Python program. Click the triangle by the project in the left pane to open it. Keep clicking until you open Book Solution Files and then double click on harvester.py. It should open in the middle pane.

Right click in the middle pane and select Run As -> Python Run. The program should run after a few seconds and a robot will harvest a field of beepers (Figure 3.2 in the book).

If you get syntax errors for my code in Eclipse, it may be that you haven't got PyDev configured correctly. Right click on the project icon in the left pane and select Properties at the bottom. Make sure that under Builders you have PyDev builder listed. Under PyDev Interpreter/Grammar make sure you have selected Python, Grammar Version 3, and the Default Interpreter. If any of those options are missing you don't have everything installed correctly.

6 Make the worlds available for all of the exercises in the book. Outside Eclipse navigate to the folder you created earlier as your workspace and find the WorldFilesDOS.zip file. Unzip this in place to expand it to a folder. Then, back in Eclipse, use the right click in the left pane and select Refresh. Now Eclipse will be able to find these files with appropriate paths. If you want to rename it (outside Eclipse) you need to Refresh again. You can rename it within Eclipse with a right click.

Notes

Note that the files in the karel folder are the simulator. They are not intended to be modified. Your code should go in the default folder (called a Package in Python). Your python files end in .py and are known as Modules in python.

Last Updated: December 8, 2014