Lecture 0 - Preparation for the first class.#

Objectives#

This is a pre-class lecture to be completed by all INF80054 students before the first class. This pre-Lecture1 note provides step by step instructions to install the required Anaconda Python package in a Windows or Mac computer. Please follow the step-by-step instructions provided in this lecture. If you have any questions, you may please raise it in the classroom.

A successful completion of Lecture 0 means that:

  1. The Anaconda3 Python distribution is installed correctly in your PC or laptop (Windows or Mac).

  2. You can launch Spyder and use its Editor to write and execute your (first) Python script.

Also, please note that Anaconda is a package which includes Spyder and many other modules. So if you install Anaconda successfully, then Spyder will be installed automatically.

Installing Anaconda3 Python Distribution#

Installing Anaconda3 on Windows#

  1. Go to https://www.anaconda.com/download/ and download the installer appropriate for your operating system. Below is detailed step by step instruction for installing in the Windows operating system. You may skip the registration if you prefer to by clicking “Skip registration” under the [Submit >] button.

Anaconda Distribution

  1. Click the [Download] button. Anaconda Download

  2. Once the download is completed, run the Installation file.

Click Open file from your Browser’s download status window) the installation file (or go to your Downloads folder where the installation file you have just downloaded is located and then run (double-click) the file:

Anaconda installation file

  1. Click Next> button on the Anaconda Installation Splash Screen:

Anaconda splash

  1. For Windows users, ccroll down the License Agreement, and after reading the agreement, click [I Agree]

Anaconda License

  1. Then, choose “Install for: Just Me (recommended)” and click Next:

Anaconda install

Then specify the Destination Folder (such as the default Windows’ user folder). You need to make sure that the Destination Folder is empty and that the full path to the Destination Folder does not contain spaces and Unicode characters. Then, click Next:

Anaconda install location

Then accept the default checked options: “Create start menu shortcuts …” and “Register Anaconda 3 …”, and click Install:

Anaconda options

Then, the Installation script will be run. This may take a few minutes to complete.

Once Installation is completed, click Next.

Anaconda completed

Then, Click Next again.

Anaconda completed2

Then, uncheck the two options (“Launch Anaconda Navigator” and “Getting Started with Anaconda Distribution”) and then click Finish.

Installing Anaconda3 on Mac#

  1. Go to https://www.anaconda.com/download/ and download the installer appropriate for your operating system. For Mac, click the appropriate download link:

Anaconda Download Mac

  1. Once the download is completed, run the Installation file.

In Windows, click Open file from your Browser’s download status window) the installation file (or go to your Downloads folder where the installation file you have just downloaded is located and then run (double-click) the file:

Anaconda installation file

For Mac users, When the download is completed, go to the Downloads location (in your Finder) then double click the installation file to run it (Note: My Mac screenshots were taken from installing a previous version of Anaconda; but it should be similar enough)

Anaconda installation file Mac

Note for Mac installation, You may need to allow and provide your Mac password to confirm:

Anaconda installation file Mac pass

  1. For Mac users, after reading the Read Me, you can proceed by clicking Continue:

Anaconda splash Mac

  1. For Mac users, read the Licence Agreement if needed, and click Continue:

Anaconda License Mac

Then click Agree to the Licensing Term:

Anaconda License Mac agree

  1. Then, for Mac users, then you may choose to install for all users, then click Continue:

Anaconda install Mac

Whatever your choice is, make sure there is adequate space in your Mac, then click Install:

Anaconda install Mac2

You may be asked to provide your Mac password (or use Touch ID):

Anaconda install Mac password

Then, the Installation script will be run. This may take a few minutes to complete.

Anaconda install Mac3

Click continue.

Anaconda install Mac4

until you received confirmation that the installation has been completed.

Anaconda completed Mac

Ensuring an up-to-date Anaconda installation#

Using Anaconda Windows PowerShell command prompt#

We now want to ensure that the Anaconda installation we have just installed is up-to-date by running some initialisation and update commands from Windows’s Anaconda PowerShell prompt.

  1. Click Windows [Start] button on your task bar and (if necessary, go to Anaconda3 menu folder) then run (that is, “click”) “Anaconda Powershell Prompt”.

Note: Your Windows system may look slightly different from the one shown in the screenshot.

Anaconda Powershell prompt

  1. In the Powershell Prompt, enter each of the following instruction one-by-one in sequence: (enter “y” if prompted to Proceed)

cd anaconda3\scripts
conda init powershell

conda init typein

conda init

Note: Your Windows powershell may appear slightly different from the screenshot.

Then close the Anaconda Powershell Prompt window.

  1. Now, re-open the Anaconda Powershell Prompt window and enter each of the following commands one-by-one in sequence:

cd anaconda3\scripts
conda update conda

conda update

Note: Your powershell may look slightly different from the screenshot.

  1. Then click ‘y’ when asked to proceed. (Note: the output you see on your computer may not match mine exactly. This is OK). You can now close the powershell when the conda update is done.

Using Mac Terminal command prompt#

For Mac users, you can open a Terminal either by navigating from Finder -> Applications -> Utilities then Double Click Terminal or using the Spotlight Search enter “terminal” and open (Press Command + Space Bar to activate Spotlight Search).

Note: YourMac system may look slightly different from the one shown in the screenshots.

Anaconda Powershell prompt mac

Then, enter this command: to make sure your installation is up to date (it is most likely is)

conda update conda

conda update Mac

Installing Spyder-Notebook#

In this course, we will use Spyder, an IDE (Integrated Development Environment) which comes with Anaconda distribution. Spyder comes together with the Anaconda package and we do not need a separate installation for it.

However, the “Sypder-Notebook” is not part of the Anaconda package and must be installed separately. The Spyder-Notebook is a plug-in which enable Spyder to open, edit, and interact with Jupiter Notebooks inside Spyder (). Note: We may not use Spyder-Notebook at all, but we will discuss further in class what Jupiter Notebooks are if necessary).

  1. For Windows users, to install Spyder-Notebook (and any other Anaconda package), run a Powershell as before then enter the following command:

conda install spyder-notebook -c conda-forge 

installing spyder-notebook

Then, tnter “y” to Proceed as prompted:

confirm installing spyder-notebook

  1. For Mac users, open a Terminal, and then enter the command:

conda install spyder-notebook -c conda-forge

installing spyder-notebook-mac

Then, tnter “y” to Proceed as prompted:

confirm installing spyder-notebook-mac

Using Spyder#

  1. There are several ways to run Spyder. First, in the Windows system, you can enter “spyder” in the Powershell prompt as shown in the screenshot below:

Run spyder

Alternatively, you can use Windows Start Menu system to:

Activate spyder

For Mac users, you can use the Spotlight Search (or navigate through Finder-> Applications ):

Run spyder Mac

Alternatively, you can enter “spyder” in your Terminal.

  1. If you are running Spyder for the first time, please feel free to take “Tour”.

Spyder Tour

For Mac users, you may be prompted to “Allow” Spyder to run:

Spyder Tour

Note: From this point on, there is no significant difference between the Windows and Mac systems. Thus, only one set of instructions (Windows based) will be provided. If there is any crucial difference between the two systems, then this will be notified accordingly.

  1. Even if you do not know any Python coding yet at this moment, do try to run example code offered by the Tour. (You may ignore it if you see the error message “This version of python seems to be incorrectly compiled (internal generated filenames are not absolute). This may make the debugger miss breakpoints.”).

![IPython]ipython.png)

  1. The default view of Spyder has three panes as shown in the screenshot below:

  • The Editor (1)

  • The IPython (Interactive Python) Console (2), which is used to run codes in the Editor Pane or entered interactively at the Interactive Python prompt in the Console, and

  • The Tabbed interfaces (3), from which you can access various information including Help, Variable Explorer, Plots, and Files.

Spyder's panels

Hello World#

  1. Now, let’s save the open temp.py file in Spyder as helloworld.py. I want to save it in a specific new folder in my user directory such as (Modify the location to use your own directory): C:\Users\apala\INF80054\helloworld.py

Hello world

Then, edit the content of helloworld.py file as shown in the screenshot below and then click the Save button on the menu bar at the top of the Editor pane.

  1. Click the Run file button at the top menu bar (or press F5) to execute the script.

Run file (F5)

  1. The output will be displayed in the Console pane as shown in the screenshot below:

Output console panel