It is not essential to use a Raspberry Pi to write programs in Python ... but it's more fun that way! That's assuming that you can actually get your hands on one of these modern marvels.
Below I describe the steps that I took to set up my Raspberry Pi (henceforth RPi) so that I could use it to write Python programs. This is not an exhaustive guide, and there are many other excellent guides on the web (for example, at elinux, h2g2, lifehacker, piprogramming or here).
You will need:
(1) Install the operating system onto your SD card. For this step you will need a PC or Mac with an internet connection and an SD card writer. (If you have bought a pre-loaded SD card (like this) then you can skip this step.)
First, download the latest version of the Raspbian operating system, available here, onto your PC or Mac. Extract the .img file from the .zip file. Insert your SD card into the card writer. Now, follow elinux's step-by-step instructions on how to write to ("flash") your SD card. Warning: If you use the "dd" command-line tool, then you must follow the instructions especially carefully to avoid the danger of overwriting your hard drive!
(2) Boot and configure.
Take a look at the Raspberry Pi Quick Start Guide, if you haven't already.
Insert the SD card into the RPi. Connect the RPi to your TV or monitor (with HDMI or DVI connector). Connect the power supply to the RPi, and switch it on at the wall. A green light should appear on the Pi, and, after a moment, scrolling text should appear on your display. If the SD card is correctly set up, then you will soon arrive at a configuration screen. Here you should choose your options, and I recommend choosing (at least):
Once you have finished, the RPi will boot to the desktop, so you should arrive at a screen featuring a picture of a large raspberry and some shortcut icons.
On my TV, the resolution is set too high for me to read the text on screen comfortably. To change this, try:
You may wish to make other changes to the config file, at your preference.
(3) Connect to Network and Update
Connect your Pi to your home hub, using an ethernet cable. Check the connection by, for example, by 'pinging' a well-known internet site, by typing at the terminal:
Now find the IP address that has been assigned to the Pi. To do this, enter
and check "inet addr" under the "eth0:" heading. It should look something like 192.168.##.## Note it down: we will use it in Step (5).
The software on your Raspberry Pi may be updated, upgraded and installed using a command line tool "apt-get". To update your Pi, enter
(The second command may take quite a while to complete).
(4) Install Python Libraries
To make the most of Python's capabilities, we need to install some standard libraries. On the RPi, new software can be installed via the command line with "sudo apt-get install <package-name>". Many libraries are already installed in the standard distribution of Raspbian, but we need two more: scipy and matplotlib. Install these with the following commands:
(5) Setup SSH access from PC/Mac
It is very convenient to be able to connect to your Raspberry Pi from another computer (for example, if someone else is watching TV!). On Linux and Mac systems this can be done using the ssh ('secure shell') command line tool. Open a terminal on Linux/Mac, and type:
where here <IP> is the IP address you found in step (3). (Presuming that you have not changed the default username 'pi'). If a connection is made, you will be prompted for your RPi password. Once successfully logged in, you will get a short message and a new prompt, something like:
This indicates that, any commands you enter will now be run on the RPi, rather than on your PC/Mac. To log out again, just type
With X-Window Forwarding, you can even use ssh to run programs that use their own windows. For example, you can run IDLE (the graphical user interface for Python) on your RPi, and get the windows to appear on the screen of your Mac/PC.
where the -X option turns on X-Window Forwarding, and then, once logged in, type:
There are two simple steps you can take to make SSH access even easier:
(a) Use an environment variable to store the RPi's IP address. On your PC/Mac, you can edit the .bashrc file, by typing
Somewhere towards the bottom of this file, add the lines
Now you can login to the RPi with the easy-to-remember command
(b) Set up password-less login. Entering your RPi password each time you login using SSH quickly becomes a drag. If you are using a Mac or Linux machine, you can set up password-less login, using RSA encryption keys (an interesting piece of maths!). Try following these instructions.