Python Installation

Instructions for installing Python, and getting started with a code editor.

I need to code right now! - www.programiz.com

programiz.com is an online code editor. This means that you can write and run Python code in your browser without having to download anything. It has a very accesible user interface and is very easy to get up and running. To be able to save your code from one session to the next you need to sign up on repl.it.

We do not recommend using repl.it for longer than necessary (at most for the first week), as it runs code very slowly.

UiO jupyterhub - https://jupyterhub.uio.no

UiO’s Jupyterhub is the University’s Jupyter notebook service. Here too you can write and run Python code in your browser without having to download anything. You log in with your UiO username and password and get access to your own environment where you can save your notebooks

When you turn in your assignments, this will be in the form of Jupyter notebooks, so it is useful to get used to this.

I have time to download Python - anaconda.com

We recommend downloading Python with Anaconda. Anaconda includes Python, together with some of the libraries we will use in this course.

Anaconda also includes the programs Spyder and Jupyter Lab, which we will use as our code editors.

Step by step:

  • Click the link above

  • Click the download button

  • Find the installer for your operating system (Pick the newer Python release, 3.7 as of writing this)

  • Follow the steps of the installer. On Advanced Options, check both boxes (there are pros and cons to checking the boxes, but this is the easiest way to get started, and will likely not be a problem at all)

Getting started with Spyder

After you have sucessfully installed Anaconda on your machine, you should be able to find and run the program Spyder. If not, open the Anaconda Navigator and find it from there.

You should start by clicking the folder icon in the top right corner to choose a working directory. This directory will contain your python files, and should be saved somewhere where you will be able to find it again.

Next, you should click the file icon in the top left corner to create a new file (or just Ctrl + N on windows). Save it as something like “hello.py” by clicking the save icon (or just Ctrl + S on windows).

Try writing print("Hello World!") in your file (using the “Editor” window on the left side of the screen) and pressing the green arrow to run it. Hello World! should have been printed in the console, the window in the lower right of the screen. The window in the upper right will probably be a “Help” window of little help, you should change it to “File explorer”.

Now you should be ready to write and run code, and create new code files in Spyder.

Official documentation: https://docs.spyder-ide.org/overview.html

I’m doing my first assignment - Getting started with Jupyter Lab

We do not recommend starting off learning code with Jupyter Lab, as it is easy to lose track of what code has been run and which variables are stored. Therefore, you should use Spyder first to learn the fundamentals. After you have learned the coding fundamentals though, Jupyter Lab is a code editor with many perks. Such as breaking up larger chunks of code into more manageable cells, making it so that your code can output plots and text after code cells, instead of in the console. You can also have cells with text(markdown cells) or images between cells of code.

To start jupyter lab you can either:

  • Run jupyter lab in the adress bar of the folder you want to open jupyter lab in (might be windows only)

  • Run jupyter lab in the terminal. This will open jupyter lab in the directory the terminal is at

  • Open jupyter lab from Anaconda Navigator

Once you have started jupyter lab you should:

  • Navigate to the folder you want your code files to be saved. (If you are not there already)

  • Create a new Python3 notebook (jupyter lab doesen’t use .py files like most other editors)

  • Give your notebook a name, and start coding

  • Familiarize yourself with the icons at the top of the notebook (save, new cell, cut, copy, paste, run, stop, restart, change cell type)

  • Note that after you have run a cell, the variables are stored and are accesible to any other cells

  • Note that the order you run cells is important, not the order cells are placed

For your assignments, download the assignment templates using the download button at the top of the page (after you have navigated to the assignment template). Then, complete each exercise using code cells below the exercise. And finally, deliver the completed assignment as a notebook file (.ipynb).

Official documentation: https://jupyterlab.readthedocs.io/en/latest/

I want to install the NLTK-library

The NLTK-library is not included in Anaconda, so we will need to download it seperately in order to use it in the computational linguistics part of the course.

Mac/Unix

  • Open the terminal

  • run conda install nltk (haven’t tested yet)

Windows

  • Open the command prompt (search “cmd”)

  • run conda install nltk

or follow the official guide: https://www.nltk.org/install.html