This repository contains sources to be used by python students. Directory projects contains the (re)sources:
- p1, p2 and p3 containing cursus_materiaal with a project description
Directory notebooks contains Jupyter notebooks that can be used in Jupyter Lab. Directory scripts contains some example Python scripts.
Watch instruction videos at YouTube
To be able to use this repository and handover your code, you need to have remote access to Github.
-
Create an account at Github
-
Install Git
Make sure you select "Checkout as-is, commit Unix-style line endings" during the installation process.
-
Install Homebrew (MacOS only)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -
Install iterm2 (MacOS)
brew install iterm2
-
Install zsh (MacOS and Ubuntu)
-
Install zsh on MacOS using
brew install zsh
In Ubuntu
sudo apt install zsh
-
Add iTerm2 path to zsh profile
echo "eval \"\$(homebrew/bin/brew shellenv)\"" >> ~/.zshrc
-
(Optional) Install oh-my-zsh (MacOS and Ubuntu)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
-
-
Install GitHub CLI (MacOS and Ubuntu)
brew install gh
Installation instructions on Ubuntu
Installation instructions on Ubuntu
NOTE
Although you could download and install GitHub CLI for Windows, I don't recommend it since it does not properly work in Git Bash. -
Create a ssh key-pair token
Start a (git) bash shell *and generate a secret key pair with your student email adress
ssh-keygen -t Ed25519 -C {your@student.email.com} -
Transfer your public key to Github
If you installed the GitHub client, you can authenticate with the following command in the terminal and select ssh for authentication
gh auth login
otherwise enter the following in (git) bash shell to view the contents of your public key
cat ~/.ssh/id_ed25519.puband paste this in the text area when adding a new ssh key in GitHub
-
Create a fork of this repository
Create a fork of MitwRdam/MakeAIWork in GitHub or use the GitHub Client by entering the following commands in your terminal
gh repo fork https://github.com/MitwRdam/MakeAIWork
-
Clone your fork If you installed the GitHub client, you can authenticate with the following command in the terminal
gh repo clone git@github.com:{your_github_username}/MakeAIWork.gitotherwise enter the following command in your (git)bash shell after replacing {your_github_username} with your GitHub username.
git clone git@github.com:{your_github_username}/MakeAIWork.git -
Configure git
In order to commit and push your changes, you need identitify yourself.
Open a (git)bash, enter directory MakeAIWork and run:
sh/git_config.sh {your_github_username} {your@student.email.com}This script will also set the pull policy to rebase.
-
Add upstream to original remote repository
To be able To be able to fetch and merge changes from this repository using (bash) commands, you need to have a (second) upstream.
If you used the GitHub client to create the fork you can skip this step, otherwise enter the following commandsgit remote add mitwrdam https://github.com/MitwRdam/MakeAIWork
-
Keep your fork repository up-todate by regularly pulling changes from the original remote repository into your local fork..
git pull mitwrdam main
and push the changes to you remote fork
git push
Enable Windows Subsystem for Linux (Windows only)
-
Check If Your Processor Supports Virtualization
-
Enable Windows Subsystem for Linux
Enter the following command in Windows Powershell:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
-
Enable the Virtual Machine Platform feature (Windows only) Enter the following command in Windows Powershell:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
Make WSL 2 Default (Windows only) Enter the following command in Windows Powershell:
wsl –set-default-version 2
To facilitate you with a managed portable isolated Development Environment, we provide a Docker image in which all dependencies are preinstalled. We prefer Docker for isolation since it is a much lighter solution than Virtual Machine.
-
Download and install Docker Desktop
-
Configure Docker Desktop
Open Docker Desktop, go to settings and select Start when you login
In Windows you can a script to enable Docker Desktop to start directly after you start Git Bash:
sh/git_bash_profile.sh
this script will also navigate automatically to the MakeAIWork directory.
-
Test your Docker installation Check if you are able to use Docker by running an example container in (git) bash
docker run hello-world
If that works, you can run the scripts to start the Docker container as described in section Python AI Workspace Usage.
-
Install python to enable the webbrowser to open automatically after starting a webservice
-
Install python
-
Install venv (Ubuntu)
sudo apt install python3.10-venv
-
Create virtual Python environment
python3 -m venv . -
Activate venv
source bin/activate
NOTE We only run Python directly on the host to sue the webbrowser module. For ad Docker Workaround on Windows, you need to install the Ubuntu in Windows sub-system.
-
-
Install Visual Studio Code
-
Enable VSCode to be opened from the command line (macOS only)
In VSCode, open the Command Palette and type 'shell command' in order to select the Shell command: Install ‘code’ command in PATH
-
Start vscode with command from current directory
Start a (git) bash shell and enter directory MakeAIWork, from there use the command code to start vscode.
cd MakeAIWork code .
-
Install the Python extension
-
Install Live Share
Follow the instructions at Collaborate with Live Share
-
Install XQuartz X.Org Window System On the MacOS host, we use xquartz to provide us with a MacOS X Window System.
Download and install xquartz
Log out and Log in to activate the changes the terminal -
Configure XQuartz to allow network connections from host
-
Get your IP address
Run the following command in the terminal to see your IP address
ifconfig en0 | grep 'inet ' | awk '{print $2}'
-
Start XQuartz
open -a XQuartz
which will open a XQuartz terminal in which you enter
xhost {Your IP}Click on the word 'XQuartz' on the top left of your screen (next to the Apple logo) and select Preference. Open the tab Security and check 'Allow connections from network clients'
-
-
Install Socat The graphical Python script runs with a Linux X Window System in a Docker container. To connect this to the MacOS X Window System on the host we use the command line utility socat.
brew install socat
-
Test by running a Python script with GUI
Instead of Git bash and Docker, you can install a complete Ubuntu terminal environment with Windows Subsystem for Linux (WSL). Although Ubuntu can be installed in minutes, you lack the benefit of all preinstalled Python modules in an isolated container.
-
Download and install Ubuntu LTS on WSL2
-
Install Miniconda
-
Install dependencies
-
Install Jupyterlab
Students use a containerised Python environment running a Docker image.
The project files are accessible in the containerised runtime environment by means of a bind mount between the directories from the current path ($PWD) on your laptop (host) and the directories in the HOME directory at the container instance:
- ${PWD}/notebooks -> $HOME/notebooks
- ${PWD}/pics -> $HOME/pics
- ${PWD}/projects -> $HOME/projects
- ${PWD}/scripts -> $HOME/scripts
CAUTION
You can remove both container and image without data loss but be aware that files removed from the container directory /project will also be removed from you host directory project.
Docker scripts can be found in docker. Each of the scripts below will call docker/run/miw_container.sh to facilitate the following runtimes:
-
REPL (Read Evaluate Print Loop) modus to experimentally learn Python commands. Exit by pressing [Control+D].
sh/python.sh
-
Start python with a script from directory project
sh/python.sh scripts/lists/sum.py
-
Start Jupyter Lab to learn from the notebooks available at project/notebooks
sh/jupyter.sh
-
Start container with an interactive bash (expert mode) to perform system operations
sh/bash.sh
NOTE
If you do not have Docker, the scripts will fall back to python and bash on your host.
Each of the above scripts will call run/miw_container.sh which will spin up a container based on the latest version of 'jaboo/miw' which is either stored locally or will be fetched from available at Dockerhub.
Inspect locally stored images with
docker imagesThe containers will be removed automatically after being terminated. For overview of both running and terminated containers enter
docker container ls -aRemoving images and/containers will not cause data loss. After removing the image, Docker will pull a new instance when you start a container. Docker images and containers can be removed (if not done automatically) by running
docker/clean_docker_artifacts.shHow to Use Linux Terminal in Windows 10
Jupyter
Running GUI's with Docker on OS X