Morten's Blog


The random output of Morten André Steinsland

Getting started with Python and Eclipse on Windows

Posted by Morten André on December 9, 2008 at 02:45. In the Tutorials category.
Tags : , , ,

Eclipse is an Open Source IDE mainly used for Java development; but with the Pydev plug-in installed it becomes a powerful Python IDE. I will now show you how to get Eclipse ready for your Python code.

1. Installing Python

Before we get started, you should check whether or not Python is already installed on your computer. Look for a folder called Python25 or something similar on your C:\ partition, also check the Add/Remove Programs list in the Windows Control Panel for any Python entries.

If Python is not installed, let’s go to www.python.org and download a copy. There are newer versions, but we’ll download Python 2.5.2 to get compatibility with many extensions. You may want to download a newer release if your not too concerned about that.

Execute the Python installer you downloaded, and follow the instructions. The default installation path is “C:\Python25“. And unless that causes problems, leave it as it is.

2. Installing Java

Eclipse requires Java. So unless it’s already installed on your system, you need to get it from www.java.com, and install it before you continue.

3. Installing Eclipse

Let’s install the Eclipse IDE. Head over to www.eclipse.org and look for Eclipse Classic which will be the release we’ll download and use.

At the time of writing, Eclipse for Windows is released as a zip archive. You’ll need to extract the folder inside the zip archive, called “eclipse“. I recommend clicking on the archive to open it, and just drag the folder to a proper destination on your computer, such as the “C:\Program Files” folder. The path to Eclipse will then be “C:\Program Files\eclipse“. If Eclipse comes as an executable installer, run it and follow the installation instructions it gives.

When the installer is all good and done, open up the folder you installed/extracted Eclipse in, and run the file called “eclipse.exe“. You may want to create a shortcut to the executable on your Windows desktop so that Eclipse can be started quickly and easily in the future.

4. Running Eclipse for the first time

If all goes well, you should be asked to choose a folder to use as Eclipse’s workspace. I recommend making a folder called “Python Projects” or something similar in the “My Documents” folder and use that as your workspace. If you want to use the same workspace folder every time, tick the check-box that says “use this as the default and do not ask again“.

Eclipse should now start without any further hassle, and greet you with a nice Welcome screen.

But we are not quite ready to start coding yet. So let’s continue.

5. Installing the Pydev plug-in

Eclipse has a nice feature that makes installing plug-ins such as Pydev a breeze. Just open up the Help menu, and select “Software Updates“.

In the window that opens up, select the “Available Software” tab and click the “Add Site” button. An input box should open up. Enter “http://pydev.sourceforge.net/updates/” and click OK.

The address you entered should now appear in the site list, letting you select Pydev for download and install. Tick the check-boxes for Pydev, and click the “Install…” button.

Review your choices and the licenses for Pydev. When ready, click “Finish“. Depending on your Internet connection, the download can take a couple of minutes to finish and install.

You’ll be asked to restart Eclipse, which is a good idea, so let’s go ahead and do it.

6. Configuring Pydev

We may need to tell Pydev where the Python interpreter is located on your computer. Select “Window > Preferences” in the Eclipse menu. Eclipse’s configuration window will open. Select “Pydev > Interpreter – Python“. If your Python interpreter is not listed, we’ll have to add it by clicking the “New…” button.

Browse to the folder where you installed Python, in our case “C:\Python25“, and select the file called “python.exe“. If all goes well, the necessary folders will be automatically included into the configuration, leaving the window looking something like this:

Click OK to save your configuration.

7. Creating your first Pydev project

Eclipse will start again, hopefully without problems. Now, go ahead and create your first Pydev project. Select “File > New > Project” from Eclipse’s menu.

A window will open, letting you choose the type of project to create. We want to make a Python program, so choose “Pydev > Pydev Project

Click Next, and choose a name for your project, location, and the Python version to use (in this case, select Python 2.5).

Click the Finish button, and voila; your project is ready to begin. Let’s create a Python source file by selecting “File > New > File” in the menu. Enter the desired file-name (in this case; helloworld.py) and parent project, so it looks similar to this:

Now, let us enter in a standard “Hello World” program.

And for the finale; click the green Run button, the one that looks like a Play button. If you get an error the first time, click on the arrow to the right of the Run button, and select “Run As > Python Run

If all goes well, the Python program should run fine, and the output should appear in Eclipse’s Python console.

Happy hacking!

Comment by Mike on September 3, 2009 at 16:05

Thanks for the walk through; it’s my first time with Python and Eclipse and your page helped out greatly!

Leave a comment

(required)
(required)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress
Theme by Morten Andrè Steinsland
66 queries. 0.163 seconds.