Python in Eclipse

There are many IDE’s available for any language, and Python has plenty to choose from. However, I’ve been programming in eclipse for Java, JSP/Servlets, Flex, and PHP for a while now and found it to be a solid IDE for at least those languages. I’ve found it to be quite good for Python, as well. If you already have something you like, then use that, of course. But for those of you computational linguists out there who are new to programming, but realize that you had better get with the computational side of things, including programming, this is where you can start.

First, download eclipse. You can either search in Google for “eclipse” and choose what you want, or you can click here. I would recommend the eclipse for PHP developers. WHY?!? Because it has built-in web tools that might come in handy later if you really get into Python. So, look to the right of that option and choose your operating system. Clicking on that link should take you to the download site which will choose the closest download mirror for you. It’s about 138 mb to download.

Once you’ve downloaded it, unzip it. If all is well, you should be able to just run it. In windows, just double-click on the eclipse file inside your eclipse folder. In linux, you may have to open a terminal, navtigate to the folder, and type: ./eclipse

If that worked, you should see the eclipse Galileo splash screen. If it doesn’t load up, the problem could be anything. One problem might be that you downloaded the wrong one for your OS. The other problem might be your java version (eclipse uses java to run). I don’t know what version it was built with, but my eclipse works fine and I am using java 1.6.16. You can check your java version in Linux (or windows) by opening a terminal (command window) and typing: java -version
If you type that and it says it can’t find java, then you don’t have it installed. So, install it. I won’t go over that here. If someone needs help with that, shoot me an email or leave a comment.

Now that your eclipse is open, you’re halfway there. Now, click on Help->Install New Software->Add. Type in “Python” in the name area and:
http://pydev.org/updates/
in the Location box and click OK. Now, you’ll see a drop-box to the left of the Add button. Click on that and find Python. Now, select the box next to “Pydev” and click Next. You may be taken to a place where you choose your mirror site (just choose any one), and you’ll need to read some licensing agreement. It will take a few minutes to download and it will ask if you want to restart eclipse when it is done. Yes, do restart eclipse.

Now, you have the ability to program in Python, but we’re not quite there yet. With eclipse open, click on File->New->Other. Scroll to Pydev, and expand the tree. Then choose Pydev Project and click Next. Type in the name of your project, anything will do. This will create a project folder for your code under the name you give. Notice that you can’t go on yet because you don’t have an interpreter. Click on the link to configure the interpreter. Now, click on Auto Config and then OK. You’ll see it spend some time looking through your computer for libraries. This means you won’t have to set your PYTHON_PATH variable, eclipse takes care of that (assuming you already installed the nltk).

When it’s done, click Next until it creates your project. You’ll see your project folder on the left. Now, expand your project folder and find the src folder. Right-click on that src folder, and select New->Pydev Module. Skip the package name and just put in a name for the file (eg, “test”). You’ll notice that it can fill in the template stuff for classes, etc., but you can just choose “none” and click OK. You should now see a new file.

Now let’s test it. First, type:
print “Hello World”

And press the green play button on top. It will ask you how you want to run the file. Just scroll down and choose “Python Run” and you can set it to autosave the file when you click run so you don’t have to. Then click OK and it should say “Hello World” in the output below.

To see if the nltk works, type:
import nltk
nltk.probability.demo()

And run it again. It should show some probabilities in the output. Now you know that you can use the nltk. You can make as many files as you’d like, classes, access those classes easily with eclipse, etc. Happy programming. Feel free to ask questions of any kind.

Leave a comment

You must be logged in to post a comment.