This page is intended to get you started on learning to code in Python using Jupyter ‘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:
- Get you connected to tools that can help you when things go wrong (they always do!),
- Learn the basics of writing code from home,
- 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 Python code using Jupyter Notebooks
What is Slack?
Slack is a “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:
- 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).
- 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.
- 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.
- 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:
- Download the Slack client for your computer and phone (Optional: you can also work directly at the Slack website).
- When creating your Slack account, use your real name as your username (so we can easily identify you!). For example, James’ username is jamesmillington
- Sign up for the kclgsa2019 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.
- Learn more about how to use Slack online.
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.
Setting 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? 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
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) so it’s important to get them set up correctly and to understand how they are used.
Over the past two years there has been an enormous proliferation of ways to run Jupyter notebooks; although this can be confusing, it is a sign of their popularity and actually means that we are now spoiled for choice and that there is a ‘solution’ to fit most applications. The ‘right’ solution depends on the stage you are at with your learning.
Code Camp (‘Trying It Out’)
STOP! This section is for Code Camp only. Look further down for the Geocomputation (Really Doing It) option.
If you’ve ended up here because you’ve followed a link online thinking “Hey, I’d kind of like to learn a bit of Python” or because you’ve been reminded by one of us (again) to do ‘Code Camp’ over the summer then the simplest way to get started is going to be Binder. This is a temporary service (i.e. you will lose your work when you log out and you will be booted out if you don’t do anything for a long time) but is a great way to get started with nothing to install and nothing to download.
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 one of the two images below!
This is a simple ‘notebook server’ view:
This is the ‘lab server’ view:
STOP! If you use Binder for Code Camp you do not need to do anything more on this page until you are ready to begin Geocomputation!
Geocomputation (‘Really Doing It‘)
For this you will need:
- Your own computer (ideally with at least 20GB of free space and 8GB of RAM as a minimum).
- Lots of free bandwidth (don’t do this over a mobile or pay-per-Gb connection!)
There are two options for running notebooks on your own machine:
- Docker; and
- Anaconda Navigator/conda.
There are plusses and minuses to each, but we’ve come round to the idea that while Docker takes up more space on your computer, it’s actually more powerful and flexible, and there are far fewer things that can go wrong when you are trying to get started.
The direct Anaconda installation is probably more ‘performant’ (things run a bit faster) and can be good training for setting up your own virtual environment later, but we feel like most of you won’t be that interested in these benefits until much later when you’ll have much a better understanding to build on.
The only (and it’s a big only) hitch for Docker is that Windows Home 10 cannot run Docker. If you are using this version of Windows you will need to install Anaconda Python directly.
STOP! We recommend using Docker unless you have an old computer with less RAM or very little space left on the Hard Drive.
We’ve posted fairly detailed instructions on the main GitHub page where we maintain our computing environment: https://github.com/kingsgeocomp/gsa_env
These will be more up-to-date than anything here (and note that this video was created in 2019, so the version of the gsa ‘image’ may now be different), but we’ve also included a video here of the installation process on a Mac:
Installing Anaconda Python
We’ve also updated our instructions for Anaconda Python on the main GitHub page where we maintain our computing environment: https://github.com/kingsgeocomp/gsa_env. However, you might still find the video below useful as it shows the installation process for a Mac (note: this was created when Python 2.7 was the safe choice – you now want Python 3.6 or greater – but the process is the same).
The next video shows the installation process for Windows 10 (which will be similar for other Windows versions).
Notes on Installation
- During installation you may be asked if you want to “Register Anaconda as my default Python”? 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.
- 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 and Jupyter Lab since it makes things that little bit easier than doing it from the command line.
- It doesn’t really matter (for the moment) whether you pick Jupyter or Jupyter Lab as they both run the same way. We kind of prefer Jupyter Lab since it’s more modern and seems a bit zippier, but sometimes we’ve had trouble showing maps and other types of complex animations in Jupyter Lab (this situation is constantly changing!).
- When you launch ‘Jupyter’ (or Jupyter Lab) from the Anaconda Navigator app, it will probably jump to your web browser and show you your ‘Documents’ folder, with your new ‘Dropbox’ folder (that you’ve hopefully installed) being ‘one level down’. In other words, scroll down the list until you find Dropbox, then click it to look inside 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.
If you’ve installed Docker then none of this is necessary!
So, 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 (below) 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.
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
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 and run 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…” (or whatever similar wording is appropriate for your browser: e.g. “Save Link 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 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:
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.