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:
- Learn the basics of writing code from home, and
- Get you connected to tools that can help you when things go wrong (they always do!), and
- 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 simple code
What is Slack?
Slack is a “messaging app for teams” that is designed to reduced email, organise conversations & topics of discussion, 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:
- KEATS is rather clunky and formal — it works well for one-to-many communication, but not so much for ‘chat’.
- Slack offers a searchable history — you will have access to this archive for the next 2 years and beyond.
- 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.
- Slack is used in the ‘real world’ by everyone from Apple to PayPal and the JPL. 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 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:
- Download the Slack client for your computer and phone.
- When creating your Slack account, use your name as your username (so we can easily identify you!). For example, James’ username is jamesmillington
- Sign up for the kclgsa2017 Slack team (with your King’s email account!).
- Make sure you subscribe to all of the available channels so that you don’t miss any updates.
Although we want to use Slack to facilitate the development of our GSA community, we will still use KEATS for all the forma aspects of the modules you take. KEATS will be used to:
- Submit coursework and take quizzes
- Host lecture slides and practical materials for you to download
- 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.
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.
Basically, Dropbox can be your saviour when you lose a USB key or forget your computer at home. But also. by using dropbox it means you will always have your files in the same directory, whether you are working on your own laptop, using the GeoCUP (more on that later) or on a campus machine. This (hopefully) will save you from having to continually change bits of your code to point to the right files (if this sentence doesn’t make sense right now, it will do in time). Ultimately, we strongly recommend you get you Dropbox if you are not already.
Getting set up with Dropbox
Getting started with Dropbox is also easy:
- Sign up for a new account.
- Download the Dropbox app for your computer and phone.
- 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?
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 ‘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:
- Running everything online (try.jupyter)
- 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 servce and there is no spare capacity on the servers) then we recommend trying option #2!
When you start the Geocomputation module in the Autumn you will still be using notebooks and Python, but we’ll running them using Anaconda Python and/or the GeoCUP system to give you more control over the code and libraries that you use. What we’re doing now, however, is the best way to get you started since it doesn’t require you to download 15GB of data to set up GeoCUP!
A modern browser
A primary requirement for using notebooks, whether online or on your own computer, is a “modern, standards-compliant browser“.
Either Mozilla Firefox or 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. However, to repeat, avoid Microsoft Internet Explorer and use Firefox, Chrome or Safari for all your browsing needs.
A secondary requirement – vital to run notebooks online but generally always useful – is that you are online! We’ll leave that to you to work 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!
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)
2. Running Python and Notebooks on Your Computer
- A modern browser (you should now have one of these)
- Python (a programming language).
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!).
To download and install the Python 2.7 version of Anaconda for your operating system from here: https://www.continuum.io/downloads. Unless you are using a very old computer, you will want the 64-bit version (see images below for which installer file to download). Note: the file to download will be >300MB (so download over WiFi!).
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. The first half of the video below shows the installation process for Mac, which is very similar to that for Windows.
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) or by typing in a terminal (cmd on 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 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:
- 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…”
- You want to save this notebook to your ‘Notebooks’ folder in Dropbox.
- 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.
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:
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.