Python Setup

This page is intended to get you started on learning to code in Python, over the next eight ‘notebooks’, we’ll be introducing you to some of the core concepts of computer programming so that we can hit the ground running at the start of term.

Aims & Objectives

The goal of this page is to get you set-up to:

  1. Learn the basics of writing code from home, and
  2. Get you connected to tools that can help you when things go wrong (they always do!), and
  3. Back up your work (see #2). We’ll be using all of this from your first day on the Geocomputation module, so it’s best that you get started now so that it’s not all ‘brand new’ to you in the practical!

With this in mind, by the end of this lesson you will:

  • Be signed up and logged in to Slack
  • Be signed up and logged in to Dropbox
  • Be ready to start writing some code using Jupyter Notebooks

Slack

Slack

What is Slack?

Slack is “messaging app for teams” that is designed to reduce email, organise conversations, and pull in relevant data from a host of other services in a flexible, fully-searchable way. All in real-time.

We want you to use Slack for four reasons:

  1. KEATS is rather clunky and formal — it works well for one-to-many communication, but not so much for ‘chat’. We expect you to want to talk about the challenges you’re facing in writing code. We promise not to think any questions you ask are ‘silly’ (see Notebook 1).
  2. Slack offers a searchable history — you will have access to this archive for the next 2 years and beyond. So if there is one thing that’s silly, it’s not looking on Slack to see if your question has already been asked before.
  3. You (and we) can access Slack on every major platform and Operating System (OSX, Windows, iOS, Android, and Windows Phone) and via a browser quickly and easily. So you can ask your question anywhere, any time.
  4. Slack is used in the ‘real world’ by developers at Apple, PayPal, and the JPL (amongst many others). This is how developers work. Last year, many students wanted to Direct Message (DM) us, which meant that others couldn’t benefit from our answers and we ended up answering the same question multiple times. This year, we will only answer coding questions that have been asked publicly in the appropriate channel.

Let’s be clear: learning to code is hard. We expect all of you to end up needing help at some point and we will not be marking down anyone who asks for help in a public Slack channel. The best way to learn is as a community — this is a very different model of learning from the ‘usual’ one in a lecture class or seminar, and we want you to get the maximum benefit from it!

Getting set up with Slack

Getting started with Slack is simple:

  1. Download the Slack client for your computer and phone.
  2. When creating your Slack account, use your name as your username (so we can easily identify you!). For example, James’ username is jamesmillington
  3. Sign up for the kclgsa2017 Slack team (with your King’s email account!).
  4. Make sure you subscribe to all of the available channels so that you don’t miss any updates.

KEATS

Although we want to use Slack to facilitate the development of our GSA community, we will still use KEATS for all the formal aspects of the modules you take. KEATS will be used to:

  1. Submit coursework and take quizzes
  2. Host lecture slides and practical materials for you to download
  3. Provide formal information about the module (syllabus etc.)

We will inform you when you will need to use KEATS for accessing materials etc, but you should remember KEATS is still a useful resource for you and you should check your module pages frequently.

Dropbox

Dropbox

What is Dropbox?

Dropbox is a cloud-based file synchronisation tool: files placed in the special Dropbox folder on a computer are automatically uploaded to the Dropbox servers, and automatically downloaded to any other computer on which you have set up Dropbox. Subsequent changes are also synchronised, and you can even go to the web interface to recover a deleted file (or the previous version of a file) as well as to download a file if you’re on a computer that doesn’t have Dropbox installed (hint: guess which computers at King’s don’t have Dropbox installed?).

Basically, Dropbox can be your saviour when you lose a USB key or forget your computer at home.

Getting set up with Dropbox

Getting started with Dropbox is also easy:

  1. Sign up for a new account.
  2. Download the Dropbox app for your computer (and phone!).
  3. Start the Dropbox app and enter the login details for your new account.

Find the Dropbox folder that has been created and drag a file (any small file) into this folder. Wait 10 seconds, and then visit Dropbox.com. Assuming that you are logged in (which you should be from step #1) then you should see this file appear in the web interface of Dropbox.

If you install the Dropbox app on your phone (and set it up with the same username and password) then after launching the app you should see the file from your computer listed there. Handy right? Don’t just use it for Geocomputation, use it to back up all of your coursework and no more worries about having to face the Office to ask for an extension!

We suggest that you create a folder in Dropbox for all your work. For example, for the notebooks that you’ll use in this introductory course, we suggest you create a folder in your Dropbox named ‘Code Camp’ or ‘Notebooks’ in which you can save everything.

Getting started with Python and notebooks

That was the easy bit. We’re now going to get you set up with the Python programming language and something called Jupyter notebooks so that you can write and run code in your web browser. We will be using Python and notebooks (Jupyter notebooks were previously known as iPython notebooks, we’ll just call them notebooks) throughout the module, so it’s important to get them set up correctly and to understand how they are used.

There are two options for using notebooks with Python:

  1. Running everything online (try.jupyter)
  2. Running everything on your computer

If you are using a fairly old computer at home then we recommend #1 as a starting point, but if you have problems with the online service (you will often get a ‘No Vacancy’ message when a lot of people are using the service and there is no spare capacity on the servers) then we recommend trying option #2! It’s what you’ll be using during the term anyway.

When you start the Geocomputation module in the Autumn you will be using notebooks and Python, but we’ll running them using Anaconda Python to give you more control over the code and libraries that you use. It will be the same regardless of whether you decide to use a cluster machine, or bring your own.

A modern browser

A primary requirement for using notebooks, whether online or on your own computer, is a modern, standards-compliant browser.

In plain-English:

Google Chrome will work well. Try to avoid Microsoft’s Internet Explorer.

Download and install Firefox or Chrome (both are free) if you don’t already have one of them. We have also found that OSX Safari works, so that should also be fine, but there are issues with downloading the notebook files so it’s often more of a pain that it’s worth. To repeat, avoid Microsoft Internet Explorer and Safari, and use Chrome for all your Jupyter needs.

A secondary requirement – vital to run notebooks online but generally always useful – is that you are online! We’ll leave it to you to work that part out 🙂

How will I know if I’ve done the right thing?

After following either of the procedures set out below to start a notebook, you’ll know you that you have been successful if your browser looks something like the image below!

Jupyter Web Application

1. Using try.jupyter.org to run notebooks online

To run everything online (option #1 above) use Jupyter’s online Python notebook service at http://try.jupyter.org/.

If you get a ‘No Vacancy’ message (like what you see below) when you access the link above, then you will either:

  • need to be patient, or
  • look at Running Python and Notebooks on Your Computer (next section)

No Vacancy

2. Running Python and Notebooks on Your Computer

Requirements

Installing Python

Python comes installed by default on some Operating Systems, but to make things simple, and so that everyone is running the same version, we want you to install Anaconda. Anaconda installs a version of Python, along with tools for installing the ‘libraries’ that provide a lot of useful functionality for your applications (more on these in a later notebook!).

You will need to download and install the Python 2.7 version of Anaconda for your operating system from: https://www.continuum.io/downloads. Note: the file to download will be >400MB, so don’t download it over a mobile connection or any other connection where you are paying for ‘traffic’.

Anaconda 4 Download
Anaconda 4 Download

Notes on Installation

  1. During installation you may be asked if you want to “Register Anaconda as my default Python 2.7”? and if you want to “Add Anaconda to my PATH environment variable”. Unless you already know something about what is being asked here, you should check ‘yes’ for both of these options (see below). On a Mac you will probably not be asked at all and Anaconda will simply become your default Python install.
  2. Once installation is complete, in your Applications folder you should have an application called ‘Anaconda Navigator’ or something similar. That is how we are going to be launching Jupyter Notebooks.
  3. When you launch ‘Jupyter notebooks’ from the Anaconda Navigator app, it will probably jump to your web browser and show you your ‘Documents’ folder, with your new ‘Dropbox’ folder being ‘one level down’ (i.e. scroll down the list until you find Dropbox, then click it to look in the Dropbox folder). You will probably want to put the Code Camp notebooks in a sub-folder inside Dropbox called, say, ‘Code Camp’. You would then launch individual notebooks by navigating to the ‘Code Camp’ folder and clicking on each notebook (with a .ipynb extension) in turn.

The first half of the video below shows the installation process for Mac, which is very similar to that for Windows.

InstallAnacondaoptions

Test everything

Now you have installed Anaconda, let’s make sure that Python and Jupyter are now working so that you can run the notebooks. We have created videos to show the process of checking installation has worked (see below) but you will also find it useful to have a look at Jupyter’s help page.

If something goes wrong: don’t panic! Sometimes there will be… complications… since every computer is unique, and sometimes something that works on 99% of systems seems to fail on the 100th. But before you think that there’s something wrong with your computer, please re-read the instructions on Jupyter’s help page to make sure that you’ve followed them fully at each and every step, and use the videos below.

If you still can’t get things to work, then Google is your friend. Read first (see the References section for a selection of informative websites and resources) and when you’ll have a clearer definition of your problem ask questions in clear and simple terms.

Testing on Windows

As it states on the Jupyter help page

(Windows): The Jupyter Notebook App can be launched by clicking on the Jupyter Notebook icon installed by Anaconda in the start menu (Windows).

This YouTube video below shows the process of checking installation in Windows, and running Jupyter from a terminal (known as the Command Prompt on Windows).

If testing from the terminal seems daunting, alternatively you can launch Jupyter from the Anaconda Navigator which in-turn can be launched either from the Start Menu or by searching for ‘Anaconda Navigator’ (hit Windows key then start typing). The process for this is very similar to that shown from 1min 18secs of the video for Mac below.

Testing on a Mac

The Mac OS X installer also offers an application called ‘Navigator’ that gives you an easy way to launch several tools for programming in Python. If you select the ‘Applications’ folder as the destination for the installation, and then look in the Applications folder (the short-cut for this is Shift+Command+A) afterwards, you’ll find the Navigator application inside the Anaconda folder. You can drag the Navigator to your launcher to create a shortcut.

When you start up the Navigator, you’ll see that the first option to ‘Launch’ is Jupyter.

We’ve got a walk-through video on YouTube:

Please have a look at Jupyter’s help page where it provides information about starting up and running the notebooks. Anaconda Python’s Navigator makes it easy to do this.

Getting Oriented with Jupyter Notebooks

In order to help you test that everything is working, and to show you how the lessons will work, we’d like you to download and run a test Jupyter notebook. But before you do so, please watch this video:

Now download Notebook-Test.ipynb while remembering that:

  1. You need to right-click on the notebook link (or Ctrl+Click if you don’t have a right mouse button) and select: “Download linked file as…” (or whatever similar wording is appropriate for your browser: e.g. “Save Link As…”).
  2. You want to save this notebook to your ‘Notebooks’ folder in Dropbox.
  3. You must check that your file still ends in “.ipynb” – using Safari this is likely to be changed to “.ipynb.txt” which will not work and is why we recommend that you use Chrome.

Moving on to the Lessons

Now that you’re familiar with the basics of Jupyter notebooks, you can move on to the lessons that we’ve created – to save you a lot of scrolling, we’ve put these on a new page:

Python Lessons

Bonus!

More about Juptyer notebooks

Now that you have your shiny new technology ‘stack’ installed on your machine, explore it! For a quick primer on how to use a Jupyter Notebook follow this nice and easy tutorial from OpenTechSchool.

The content and structure of this teaching project itself is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 license, and the contributing source code is licensed under The MIT License.