Installing and Running Python on Your Own Computer

Running Python

Python is a text-based programming language where you give the computer lines of instructions (or “code” ) that are interpreted and run (or “executed” ) by the Python interpreter. These can be entered one line at a time on a commandline interface, or as a sequence of instructions written as a programme or “script”. In these notes we will concentrate on writing scripts, as these are more useful in the long run.

Several interfaces are available after installation, with the Jupyter Notebooks interface also having some online cloud-based implementations.

Installing Python

Some computer systems come with a basic Python setup already installed. However, you should make sure you have your own version of Python which includes some useful extra packages and an editor or Integrated Development Environment (IDE) to write and run (execute) your Python scripts.

The quickest way to obtain a complete Python system is to install a Python distribution such as Anaconda Python.

Download Anaconda Python Version 3 here (free):
https://www.anaconda.com/distribution/#download-section

Launching from the Anaconda Navigator

The Anaconda main interface is the Navigator (found under All programmes > Anaconda 3 in the Start menu), from which you can launch all installed delevlopment tools.

The Jupyter Notebook interface

Jupyter Notebook is a popular interactive environment for running blocks of Python code. It runs in a web browser and output is displayed inline for ease of use and visibility. Individual parts of the code can be put into their own blocks and run separately or all in sequence. The complete code can be saved as a python script .py file to be run by other people or as a web-page (html) or a pdf for a report.

Launch Jupyter Notebook (e.g. from the Anaconda Navigator):

  • From the Start menu under Anaconda on Windows:


Instructions for Use:

A notebook file menu will appear in your web-browser (usually displaying your Home/User folder) along with a black terminal window (do NOT close this!).


  • Click on the New tab and select Python 3 to start a new Jupyter Python 3 notebook:


  • Click on the title "Untitled" (next to Jupyter at the top) to change it:


  • Enter a name (do not use spaces!) and click Rename:


  • You can now enter code into code blocks and press SHIFT\(+\)RETURN to run

    • or use the black triangle (“run button”).

    • click on the block to edit it.


  • Output appears below each input cell.

  • Error messages also appear below to help you debug your code.

Entering formatted text in Markdown cells

You can also change a block to enter text using Markdown syntax (see here for more info).


This uses special characters (Markdown) to tell the notebook how to format things, and equations can be entered using special syntax (called \(\LaTeX\) maths).


When the block is run the text appears fully formatted:


You can then download the contents of the notebook in various formats for sharing them:


The Spyder IDE

This is an Integrated Development Environment (IDE) specifically designed for Python programming combines a programming text editor with a command line interface. We can write and run a code using the same program as well as see the output including any graphs directly. The interface looks and functions a lot like Matlab, making it easier to transfer between the two.

Launch Spyder (e.g. from the Start menu -> Anaconda -> Spyder on Windows):


The following should appear after a short delay:


On the left you see an editing window for entering commands and programming.

On the right are two panes:

  • the top one shows various information and

  • the bottom one any output from running the Python script.

You may want to drag the bar in between the panes to resize them.

Starting a New Script

  1. Click the first icon (a white page) and a new script file called “untitled.py” inside a folder in some useful location sucha as Deskdop > Python. This is where all your files should be kept.

  2. Change the name to something like “new_script.py” (Do NOT use spaces in filenames!)


Now you can start entering commands, as in the course booklet.

  • Press Run (green > arrow) or hit F5 to run your code

    • a window may pop up the first time you do this. Just press Run

Notice that errors appear in red in the output pane on the right:


  • Just try reading them to make sense of what went wrong.

    • Here we didn’t tell it what y was so just change that and run again:

The output now appears in the output window (or plots can appear in the “plots” tab in the top right pane):



Running an Interactive Commandline Interface

Python can also be run interactively through a console or command line interface where you type each instruction separately and press Return (or Shift Return) to run them one at a time.

A console can be started from the Anaconda navigator in the Start Menu Anaconda group:


To run commands interactively:

Type commands one at a time (maximise the window if needed).