ICS4U – Getting Started With Python

ICS4U Learning Goals

In this ICS4U lesson you will be learning how to:

  • Download and install Python to your computer
  • Use an Integrated Development Environment to write a python program
  • Install 3rd party python packages to your device

Python Programming Language

ICS3U ICS4U Python Image

The programming language of choice in this course is Python .  I am aware that some of you will have programmed in different languages in Grade 11.  There really isn’t much i can do to change that, but its the skills from grade 11 are what were important.  So if you were a good coder in grade 11, it shouldn’t be too much of a chore to pick up a new language pretty quickly, and you will need to put in some extra effort right away to get caught up with the essentials of Python.  If you have any interest in computer science as a future career, working with different languages is essential.

Python is an Interpreted language and thus needs the python interpreter to run the code.  We can run that interpreter on our machines or through a server on the web.  For some of the learning activities I’ll just have you type the code into a web editor and run the code from there, other times you’ll need to create and run the code from  software on your computer.

  • A proper computer PC / Mac is required in this course.
  • Tablets/Chromebooks running cloud based IDE’s won’t be good enough for the entire course.

The first thing you will need to do is setup an IDE (Integrated Development Environment) o your computer to run Python.

  • Any Python v3.XX is appropriate. (Definitely do NOT use v2.XX as there are significant differences)
  • I have some recommended IDE’s for you to use (That I will outline below), but you can use something different if you want as long as you can figure out how to install some specific packages with them that aren’t included with the python base installations.
Note:  Python files have the extension .py  If you are trying to send these .py files over the HWDSB email system, the school board will flag them as a dangerous file and remove the attachment.  
 

Integrated Development Environments

Option #1 - IDLE

This is the most straightforward and lightweight way to create and run python programs on your computer.  It comes built in when you download python from python.org. 

IDLE Demo

  • Watch the video below for a demo on how to write a program using IDLE

Installing additional Packages

Later on in the course you will need to use some 3rd party packages for your projects.

  • Pygame -> We can make some simple games using this package
  • OpenCV-python -> We can use this do some video processing using a webcam
  • Numpy -> We can use this to do some more efficient math calculations
  • Mediapipe -> We can use this to do some computer vision applications

To install these packages and be able to use them with IDLE, we can use a package management system called PIP.  To access PIP you need to open a Terminal Window on your computer.  

  • Windows -> Search for “cmd” in the Windows Search Bar and it will open up a terminal window.
  • Mac -> Press the “Command” button and the space bar simultaneously then search for “Terminal” 

To actually install the packages, you need to just type the following in your terminal window

  • pip install packageName
  • Note: on Windows you will likely need to type
    • py -m pip install packageName

Option #2 - Pycharm

Pycharm is another very popular IDE that is used to create larger python projects.  This is the IDE I use to create all my projects

  • You would want to use the Free “Community” version that is available to download. 
  • There is an educational version as well free to students, but you would have to sign up.  (Always beware of giving personal information away to companies)

Pycharm has a nice project management system allowing you to manage multiple files easier than IDLE.  

It is also easier to manage packages for each project that you code. 
  • You don’t need PIP to install the packages in pycharm, look for the package manager at the bottom of the IDE and you can search an install from there.
 

HWDSB - SCHOOL BOARD MACHINES

Both IDLE and Pycharm can be installed from the Software Center on the HWDSB school board machines.  

  • The school board restricts cmd line usage so getting the packages metnioned above installed using pip for IDLE will be a challenge without a teachers help (who knows what they are doing).  Pygame is installed by default, so the only issue that will arise will be if you tried the code from the Emerging Tech Unit.  Otherwise the entire course can be completed using IDLE as your IDE
  • Pycharm on a school board machine is better as you should just be able to use the package manager to install anything you need.

Option #3 - VSCode

Another popular choice is VSCode.  I don’t use it too much, but feel free to try it out and see if you can figure out how to configure it with the required packages install.  I believe if you access the terminal from within VSCode that you can pip install whatever you want.

ICS4U Activity

Install the base version of python and the required packages using PIP

  • Download and install an IDE of your choice.  
  • Install the packages listed above
  • Create a program called “demo.py” and enter the code below.  
  • Get the program to run on your device
  • If the code runs without errors then they installed successfully in the correct location.
  • Make sure you are able to find that file in your file system so when you do assignments you can hand in your work.
				
					import pygame
import cv2
import numpy as np
import mediapipe as mp

name = input("Enter your name: ")
print("Hi",name)

				
			

ICS4U Activity

Go to the discussion forum on the HUB 

  • Send your teacher a message indicating if you have successfully installed a working IDE with the correct packages installed.
  • Let him know if you are having any issues or if you are using a different IDE then recommended.

Return to ICS4U Main Page