This project will show you how to create your first program using Python, the programming language for beginners.

First of all we need to install the programming software Geany, we are using the Fedora operating system for this tutorial.

In the Gnome system menu, go to Accessories and select Root Terminal.
You may be asked to enter the root password to continue.

Root terminal

We will now use the command terminal to download and then install the Geany programming software.
In the command line type apt-get install python geany xterm and press enter to run the command.

Geany install

You will be told that the installation will use just over 9MB of storage space and you will be asked if you would like to continue. Press Y and press enter to continue.

Geany installed
The installation of Geany is now complete, you may now close the terminal.
We will now open Geany from the Gnome system menu by going to Programming and then selecting Geany.

You can now open Geany!

Once Geany is open, click on the File menu and navigate to New (with Template) and select main.py this will now open a new Python file for us to create our program with.

Creating a new file

When opening a new Python file, Geany automatically inserts unnecessary code.
As only the first line is needed for us to create our first program I usually delete the code so that only the first line remains.

Delete unnecessary codeWe are going to keep our first program very simple – When the program is run it will display a line of text.

Within the second line of the code type Print.
Notice how the word “Print” will change to purple which demonstrates that Geany has recognised Print as a function.

Print function

Insert a space after Print and enter the line of text that you would like to be displayed in the program within brackets.

Print text

Now click on the cogs icon to run your first program!

Run program
Your first program will now open in a new Window, although it’s only a simple program you should be proud of yourself!

Your first program!

 

17 Comments

  1. ademcan
    March 1, 2012

    Hi,
    Thank you for this interesting post.
    I thought that the RPi was delivered with a Fedora version, but you used apt-get to install Geany. Do you have Ubuntu on your RPi ?
    I am getting every day more and more impressed by this computer :)
    I hope to have one as soon as possible.
    Thanks.

    • Jim
      March 1, 2012

      We are hoping to get our hands on one soon as well. Because we do not yet have a raspberry Pi in our hands, all testing has been done on virtual machines etc. Once the kit is with us then we can really crack on and build up our project library. Best of luck getting your hands on one, and enjoy it when you do.

  2. Abbas
    March 7, 2012

    Hi,

    I can’t wait to own a Rasberry Pi and start writing programs!

    Please hurry up and release the next batch of stock! 10,000s of us are waiting!

    Regards

    Abbas

  3. Ben
    May 29, 2012

    Hi.
    Great post, just got a tip for you.
    The RPi comes with Geany and Python, so if when you get a Pi, you won’t have to install it.
    Thanks

    • Jim
      May 29, 2012

      Thanks for your tip. Our RPis are awaiting shipping so we can really test them out soon. Thanks for stopping by and taking the time to post.

      • gregor
        June 11, 2012

        my pi arrived on friday and i have been fiddling around with scratch and other programs but this one step further. Any more programs to write?

        • Toby
          June 19, 2012

          Hi Gregor, we will be posting similar tutorials in the future!

  4. Richard
    June 20, 2012

    Just a small word of warning for novices: when you first click on the ‘cogs’ button to run your code you may get an error message as follows:

    Could not find terminal “xterm” (check path for Terminal tool settings in Preferences)

    That’s what happened for me, straight out of the box with Debian Squeeze pre-installed on an SD card I bought on eBay. (Your own setup may differ…)

    Select edit… preferences… tools and change the Terminal: entry to read:

    /usr/bin/lxterminal

    That’s what I had to do, anyway.

    • Jim
      June 20, 2012

      Thanks for the tip Richard, it’s tips like these that really build the community.

    • Allan
      July 6, 2012

      Hi Richard, I’m new to all this. I’ve got the same SD as you. What is the root password on the root terminal? I’m going nuts trying to figure all this out. It’s reckoned to be simple stuff but I can’t even get started.

  5. Jeff
    July 2, 2012

    Hi all, ran into the same problem as Richard with the ‘xterm’ error. However, I can’t save any kind of changes to the preferences. It just reverts back to xterm. Also can’t change the date/time on the system, etc. Anyone have this problem?

    • Jothi
      January 15, 2013

      Hey jeff, I am having the same problem currently, did you ever solve it?

  6. Tris
    July 5, 2012

    Don’t want to be Buzz Killington here, but if this is for total noobs, there are a couple of clangers that really need to be addressed.

    If they’ve managed to get Fedora up and running, “apt-get install geany” will not work. Surely under Fedora they’ll need to run “yum install geany”. Mind you, someone’s pointed out that Geany’s already installed, so that won’t be an issue. However, using yum to install rather than apt-get is what I’m getting at.

    Also, the Program line says “Insert a space after Print and enter the line of text that you would like to be displayed in the program within brackets”. The text is expressed in double quote marks “” not brackets ().

    Don’t want to confuse them before they start!!

    Have ordered my Pi. Can’t wait for it to arrive. David Braben rocks!!

  7. Robert Maguire
    July 6, 2012

    You can try using the ‘SUDO’ command before trying to save any changes, this gives you the authority to change files.

  8. tom
    July 7, 2012

    Hi
    I did everything you said but it says it cant find terminal “xterm”

  9. Robert Maguire
    July 8, 2012

    Ubuntu won’t currently run on the Raspberry Pi, if ever. There are, however, other Pi like computers it will run on like the Gooseberry. This does not have an Ethernet connection though, you have to use WiFi, it is basically an A10 board from a tablet so it will also run Android. It also has the extra boost of being about three times faster than the Pi.

    Also take a look at the OLIMEX / OLINUXINO which is compared to the Pi because it runs a Linux system, but is very different, or the DuinoMite which actually come with a version of BASIC on-board, just like the old BBCmicro. I purchased a couple of these and had my first interfacing project programmed, finished, and running in 3 hours from first setting eyes on this mini computer. These are superb little computers.

  10. Philip Davey
    December 28, 2012

    Done that and got it to work! Now on to the next!