Course material

by Jochen Köhler, 23./24.10.2020 / online

View the Project on GitHub jochenkohler/INFRa_course_material_JK

Getting started with Python

If you find mistakes/typos or links that do no longer function, please contact:

Jochen Köhler (jochen.kohler@ntnu.no)

Install Python 3.7

First, make sure that you have python 3.7 installed. To verify that, open a terminal window. You may do this:

Once you have a terminal window opened, type the following command (note that the dollar symbol indicates beginning of command, but should not be typed in the command window):

$ python -V

If you need to install Python 3.7 on your computer, here are some guides:

Install Anaconda

Now install Anaconda. This depends on your operating system:

MacOS

Make sure you are working on a zsh terminal. Type the following command:

$ chsh -s /bin/zsh

And restart your terminal. It should say – ~ – -zsh on top.

Now install Anaconda. Try the instructions in this link first. If you have trouble doing it this way, you may look at this other link. After you have installed it, run this command:

$ conda init zsh

Windows:

Use this link.

Verify Spyder version

To check installed Spyder version:

$ conda list Spyder$

If Spyder is correctly installed, you should see the following output:

# packages in environment at /Users/usrname/anaconda3/envs/tktpy:
#
# Name                    Version                   Build  Channel
spyder                    4.1.3            py37hc8dfbb8_0    conda-forge

If Spyder is not installed:

$ conda install -y spyder

To update Spyder to the latest version (20.08.20 is 4.1.3):

$ conda update -y spyder

Python packages

Create a conda environment called tktpy:

$ conda create --name infrapy python=3.7

Once the process is finished, check that it has been successfully created:

$ conda info --envs

It should show at least an environment called base (with a * next to it) and another called tktpy. The * means that the current environment is base. We need to activate the environment we want to work at. For that, type the following:

$ conda activate infrapy

Next, you need to install the course requirements. These are the python packages that we will use during the course. They are stored in a file called ‘tktreq.txt’. To download the file, type:

$ curl -OL https://raw.githubusercontent.com/jochenkohler/INFRa_course_material_JK/master/infreq.txt

To install them, type the following command:

$ pip install -r infreq.txt 

Jupyter

Jupyter notebooks are created for pedagogic purpose. You can use Jupyter Notebooks or Jupyter-lab to view/edit notebooks. To use widgets (interactive boxes) follow these instructions: To install jupyter-lab (assuming that conda is installed):

$ conda install -y jupyter jupyterlab nodejs

Then, install the required widget extensions with the following commands:

$ pip install ipywidgets
$ jupyter nbextension enable --py widgetsnbextension
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager