Scientific computing with Python

by Conor Lawless email: conor.lawless@ncl.ac.uk

Installation

The first step on the way to using Python is to have the Python interpreter installed on your machine. The interpreter takes a Python script (a simple text file that you will write), checks that it can understand it (that it is written correctly in the Python language), and if so, it executes the instructions contained in the script. If the interpreter finds a language error (a syntax error), it helpfully tries to tell you about it and pinpoint the error so that you can correct it.

Installation difficulties specific to Newcastle University

Unfortunately, due to our university's security policy, it is no longer possible for students or staff to manually install Python onto university desktop machines. Generally, computing is much more straightforward if you have administrator rights on your machine. You can request administrator rights on a Newcastle University desktop machine to allow you to work more effectively, however the default university policy is not to allow this. In the absence of administrator rights, you can request that your institute's computer support team install Python (and any libraries required) onto your computer. Newcastle's IT department has expressed its full support for increasing the programming skills of biomedical students & researchers and will help. Please let me know if there are any problems. Python has been pre-installed on all of the machines in the Dene cluster (which is accessible by all) and should remain installed on those machines for the foreseeable future, however many useful libraries are currently missing.

Installing Python & add-on packages simultaneously

One difficulty with using Python for serious scientific computing is that it typically requires the installation of a range of add-on libraries. One way to avoid this issue is to install a version of Python that already has all of the most popular add-on libraries pre-installed. This can be a great thing to do if you want to try out a lot of different libraries. However, since the installation files are quite large (~350Mb) we won't install these packages during the workshop. Feel free to try them out on your own if you have some time. The two most popular scientific computing packages for Python are Google's pythonxy and Continuum Analytics Anaconda.

Downloading Python

Microsoft Windows

We can download installers for Windows from the Python download page. Unless you have a specific reason not to (for instance, working with datasets > 2Gb in size) you will have an easier time of it if you install 32-bit Python, regardless of whether your computer is a 64-bit or a 32-bit machine. NOTE: Check "Add Python to PATH" if presented with the option. It will allow you to run Python from the command-line, which is very useful.

Linux

Python 2.7 is installed by default on all versions of linux. You can verify this by opening a terminal window and entering python at the command line.

OSX

OSX is based on Linux and also has Python 2.7 installed by default. The pre-installed version can be used directly (e.g. enter python at the command line after opening a terminal window), however, many OSX users install a separate version of Python, using Homebrew (a package manager for OSX).

Which version of Python?

There are two main versions of Python available: Python2.7.11 and Python3.5.1. Many people still use the older version of python (2.7) which is still occasionally updated. It won't make much difference for our purposes, but we will use Python 3.5 today, where possible.


OverviewInstallationFirst ScriptExecutionLibrariesStructureOther Resources


Last updated: April 2016