Eclipse Python Setup
A tutorial about how to use Python in Eclipse.
At first we will need to install Python itself. Therefore we visit the official Python Website, navigate to Download and download a Python version. There are two options right now:
- Python 3: contains a new concepts, is faster than Python 2.
- Python 2: is simpler than Python 3.
We love simplicity, so we will go for Python 2. The Python developers are still updating Python 2 regularly, so we will do just fine with it.
Now that we know which Python version we want to use, we will download the Python 2.x.x Windows installer from the Python Download Page:
As soon as the download is finished, we simply install it.
Our computer now knows how to execute Python code, great!
Eclipse will be our development environment (IDE). It's like a big set of tools that makes our lives easier later.
Be warned: the rest of this tutorial may look rather long. The reason is that we will explain every single step so everyone understands how to do it.
To get Eclipse, we head over to Eclipse.org, navigate to Downloads and then download Eclipse Classic:
Once downloaded, we can see a Eclipse zip file in our Download folder. Now we just extract it with a program like 7zip to wherever we want (for example to C:\Eclipse) and then we start the eclipse.exe file inside it:
Once started, Eclipse asks us something about a Workspace. Just press OK there.
Now Eclipse is up and running, but we are still kind of in the welcome menu. Let's click on Workbench:
Congratulations, we can now work with the Eclipse IDE:
You might noticed that Eclipse has Java written all over it. The reason is that Eclipse is usually used for Java programming, but due to its plugin system, it works with all kinds of languages (like Python) as well.
So let's install the Python plugin really quick, then we can jump into programming.
In Eclipse, we select Help -> Install new Software. In the Install window we click Add and then enter http://pydev.org/updates as Location and pydev as name:
Afterwards pre press OK and wait a few seconds.
It now shows two PyDev things in the list:
Make sure to select both of them and then keep clicking Next and Accept the terms... until the installation was finished. If it asks if we trust the certificate, make sure to confirm it.
Once installed, Eclipse wants to do a restart, so let's just press OK and wait until Eclipse restarted itself.
Remember how we installed Python in the beginning? We still have to tell Eclipse that we did that, so let's go to Window -> Preferences -> PyDev -> Interpreter - Python to see the following window:
In there we press the Auto Config Button which should find python:
Afterwards we press OK in the Preferences window and wait while Eclipse restarts.
The Eclipse Python plugin is now set up successfully!
Note: we won't have to do anything like that again, this was a one time setup.
Creating the first Project
Let's take a look at how to create a Python project in Eclipse. Therefore we go to File -> New -> Project...:
In the New Project window we simply select PyDev Project and then press Next:
Now all we have to do is enter a project name and then press Finish:
If Eclipse asks if it should open the associated perspective, we press Yes.
Now Eclipse shows our Project in the Project List:
Let's create a new Python source code file by right clicking the Project and then selecting New -> PyDev Module. Eclipse wants to know a name for the file, so let's enter mainfile:
Then we press Finish. If eclipse asks us for a template, we select Empty.
Now we can see the new mainfile.py module in our Project:
The part in the middle is our source code (where it currently says Created on...). The green text in there is just a automatically generated comment that we can delete if we want to.
A Python Hello World Program
Now the exciting part, let's create a program that shouts Hello World. The code for it is rather simple:
print 'Hello World!'
After saving it (Ctrl + S or File -> Save) our Project looks like this:
So the last question is, how do we run it?
This is very easy, we just right click our mainfile.py:
and select Run As -> Python Run.
And suddenly the Console windows greets us with Hello World!:
That's it, Python in Eclipse.