Skip to content

AmadLaghari/MakeAIWork

 
 

Repository files navigation

MakeAIWork

Projects

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.


Python AI Workspace Installation

Watch instruction videos at YouTube

Clone this Git repository

To be able to use this repository and handover your code, you need to have remote access to Github.

  1. Create an account at Github

  2. Install Git

    Make sure you select "Checkout as-is, commit Unix-style line endings" during the installation process.

  3. Install Homebrew (MacOS only)

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  4. Install iterm2 (MacOS)

    brew install iterm2
  5. 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)"
  6. 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.

  7. 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}
  8. 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.pub

    and paste this in the text area when adding a new ssh key in GitHub

  9. 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
  10. 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.git

    otherwise 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
  11. 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.

  12. 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 commands

    git remote add mitwrdam https://github.com/MitwRdam/MakeAIWork
  13. 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)

  1. Check If Your Processor Supports Virtualization

  2. Enable Windows Subsystem for Linux

    Enter the following command in Windows Powershell:

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  3. Enable the Virtual Machine Platform feature (Windows only) Enter the following command in Windows Powershell:

    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  4. Make WSL 2 Default (Windows only) Enter the following command in Windows Powershell:

    wsl –set-default-version 2

Install Docker Desktop (Windows and MacOS)

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.

  1. Download and install Docker Desktop

    Download for Mac with Apple M* chip

  2. 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.

  3. 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.

  4. Install python to enable the webbrowser to open automatically after starting a webservice

    1. Install python

    2. Install venv (Ubuntu)

      sudo apt install python3.10-venv
    3. Create virtual Python environment

      python3 -m venv .
    4. 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.

Edit with Visual Studio Code

  1. Install Visual Studio Code

  2. 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

  3. 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 .
  4. Install the Python extension

  5. Install Live Share

    Follow the instructions at Collaborate with Live Share

Run Python scripts with Graphical UI in Docker (MacOS only)

  1. 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

  2. Configure XQuartz to allow network connections from host

    1. Get your IP address

      Run the following command in the terminal to see your IP address

      ifconfig en0 | grep 'inet ' | awk '{print $2}'
    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'

  3. 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
  4. Test by running a Python script with GUI

Ubuntu in Windows sub-system (alternative for Windows users)

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.

  1. Download and install Ubuntu LTS on WSL2

  2. Install Miniconda

  3. Install dependencies

  4. Install Jupyterlab


Python AI Workspace Usage

Students use a containerised Python environment running a Docker image.

Files available to the container

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.

Scripts to use Python

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.

Docker artifacts

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 images

The containers will be removed automatically after being terminated. For overview of both running and terminated containers enter

docker container ls -a

Removing 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.sh

References

How to Use Linux Terminal in Windows 10
Jupyter
Running GUI's with Docker on OS X

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Jupyter Notebook 52.7%
  • Python 40.6%
  • PureBasic 5.3%
  • Other 1.4%