Appendix A — Setting up your machine

This section covers all the steps needed to set up your machine in order to follow the labs sessions. The technological stack used for this module is composed of the following main components:

Tip

Section 2.1 provides a more detailed description of what every component does, and why are they needed.

A.1 Install Anaconda

You will need to install Anaconda distribution your machine if it is not already installed. You can run the following command to see if it is already present in your system:

Terminal
conda --help

If you get a command not found error, you will need to install Anaconda. You can do so by:

  1. Download it from the official website: https://www.anaconda.com/download
  2. Execute the binary you downloaded in previous steps and follow instructions
Figure A.1: Download the right version for your system from Anaconda’s website

Once you’ve done it, Anaconda, Python, some popular libraries and a software called Anaconda Navigator will be installed in your system. We will be using Anaconda Navigator as an interface (GUI) to Anaconda.

A.2 Create a virtual environment

Important

You will only need to do this step once per machine. After the virtual environment is created, you will not need to create it again, unless you delete it or you want to use it in a different machine.

  1. Download the file environment.yml in your laptop
    1. Right click on environment.yml and select “Save Link As…”
    2. Create a folder dedicated to IM939 (where you will be adding your notebooks and exercises) and save it in there without changing its name.
  2. Open Anaconda Navigator
    1. Click on Environments’ tab
    2. Click on Import
Figure A.2: Import environment from Anaconda Navigator
  1. Select the file environment.yml you downloaded on the previous step.
  2. Write IM939 as the environment’s name
Figure A.3: Select the file
  1. After downloading the required packages and installing them (this can take time), an environment called IM939 will be created
Figure A.4: Anaconda Navigator displaying the newly created environment as the active environment
Command Line alternative

Instead of using anaconda navigator, you can also do the same from the command line.

Open your terminal and type the following command:

Terminal
conda env create -f environment.yml

A.3 Activate the virtual environment

Important

You will need to do this every time you restart your session. Prior to every lab session, you will need to make sure that the IM939 environment has been activated.

To activate an existing environment you need to:

  1. Open Anaconda Navigator
  2. Click on Environments’ tab
  3. Click on IM939 to activate it. After a brief lapse of time, you will see a green border and arrow next to it, indicating that the environment has been activated.
Figure A.5: Anaconda Navigator showing IM939 as the active environment, and a listing of every library and versions installed.
Command Line alternative

Instead of using anaconda navigator, you can also do the same from the command line.

Open your terminal and type the following command:

Terminal
conda activate IM939

You will see that the environment is active because you will see its name in the command line.

Warning

If you do not activate the environment, chances are that the code will not work due to missing libraries or using different versions of some libraries. Image below shows how the same command (import altar as alt) yields an error on Figure A.6 (a) because the environment has not been activated, whereas Figure A.6 (b) shows that the same code just works after activating the environment using the command conda activate IM939.

(a) Error caused by not loading the environment
(b) IM939 activated does not trigger any error
Figure A.6: Running the same command yields different results depending on whether the environment has not been activated (A) or it has been activated (B).
Tip

Did you notice that the terminal on Figure A.6 (a) shows (base) next to the command prompt, whereas Figure A.6 (b) shows (IM939) instead after having activated the environment?

You’ve guessed right: this is how the terminal will tell us which is our current environment.

A.4 Working as usual

Now that the environment has been created and activated, you can use your jupyter notebooks using your favourite IDE, like you would do normally. For your convenience, the environment includes Jupyter Lab (and some extensions).