Skip to content

IPP-CFG-01-001 #29

@labbenchstudios

Description

@labbenchstudios

Description

  • Although the exercises are designed to run on any OS that supports Python 3.10+, there may be some OS-level dependencies in later lab modules (particularly for I/O and connectivity exercises) that - as of this writing - may not function properly in non-Linux environments. To avoid these issues, you may want to install and configure a Linux-based development environment on your local system.

Review the README

  • Please see README.md for further information on, and use of, this content.
  • License for embedded documentation and source codes: IPP-DOC-LIC

Estimated effort may vary greatly

  • The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.

Important Note on Examples

  • Most examples and shell script samples are shown using a Linux-based command line, whether via Windows 11 and WSL v2, macOS terminal, or a Linux terminal. Some commands may need to be altered if you're running exclusively within Windows.

Actions

IMPORTANT NOTE: Many of these steps can be done from within your IDE (e.g., VS Code or PyCharm). However, I think it's important to know how to use Git from the command line. Therefore, these instructions walk through the commands to issue from your terminal (e.g., console window).

Step 1: Select your Operating Environment

  • Choose an installation approach based on your development system's operating environment:
    • Windows:
      • Option 1 (recommended): Use Windows Subsystem for Linux. If you're using WSL v1 and / or Windows 10, you'll need an X11 display server for Lab Module 04. This should not be necessary with Windows 11 and WSL v2, as an X11 display server is included.
      • Option 2: Use a Virtual Machine image (i.e., Ubuntu or other Debian-derived Linux operating environment). There are many virtualizer products available to support this approach, including VirtualBox.
    • macOS:
      • Option 1 (recommended): Use the native OS as is, install Python using brew or directly from python.org.
      • Option 2: Use a Virtual Machine image (i.e., Ubuntu or other Debian-derived Linux operating environment). There are many virtualizer products available to support this approach, including VirtualBox.
    • Linux (Debian-based, such as Ubuntu 20.04LTS or higher):
      • This is the preferred environment.

Step 2: Install the latest version of Python 3 (if not already installed)

  • Your system may already have a current version of Python 3 installed. You can check by doing the following:
    • Open a terminal window or console
    • Type: python --version --or-- python3 --version
    • You should get something similar to the following as a response (version may differ - as long as it's 3.10 or higher, you should be good to go - nothing more to do):
      • Python 3.10.12
    • The python command may fail - that's fine as long as python3 works. If you get an error like the following (Linux), you'll need to install.
         Command 'python' not found, did you mean:
           command 'python3' from deb python3
           command 'python' from deb python-is-python3
      
    • NOTE: On Windows 11 using the Command Prompt, python --version should work
  • Python3 installation

Step 3: Install Git Locally and Create an Online Git Account

Install Git Locally

Create an Online Git Account (if you don't already have one)

  • If you do NOT have an online Git account (GitHub, GitLab, BitBucket, etc.)
    • Choose one of the available online Git services (examples in class will use GitHub)
      • E.g., GitHub, GitLab, BitBucket, or any other that fully supports Git
    • Follow instructions to create your account. The following are just examples. Use a Git-compatible service of your choice:

Create a New Repository within Your Online Git Account

  • Log into the online Git service you've selected
  • Create a new private repository
    • The name can be anything you'd like - some examples:
      • E.g., ipp-exercise-solutions
      • E.g., info5002-exercise-solutions
  • Copy the repository URL - you'll need it later

Step 4: Clone and Configure the IPP Sample Repository on Your Local System

Create the IPP Home Directory

  • Open a terminal on your system (select one of the following):
    • Windows Console
    • Windows WSL terminal
    • Ubuntu terminal
    • macOS terminal
  • Create a directory for your Intro to Programming in Python repository
    • NOTE: This can be anywhere you'd like, and you can name it anything you'd like; however, I'd suggest using ipp in your HOME directory
    • Using Windows
      • cd %USERPROFILE%
      • mkdir ipp
      • cd ipp
    • Using WSL, Linux or macOS
      • cd $HOME
      • mkdir ipp
      • cd ipp
  • This new path, ipp will be referred to as IPP_HOME

Clone the IPP Sample Repository

  • Open a terminal and go to your IPP_HOME and clone the main respository for the course:
    • NOTE: Remember that IPP_HOME is shorthand for your IPP code install directory
    • cd IPP_HOME
    • git clone https://github.com/programming-in-python/ipp-exercise-components.git

Configure Your New Respository

  • Change the remote destination for your closed repository

    • Remove the original remote
      • git remote remove origin
    • Add and verify your new remote
      • ```git remote add origin {your new repository URL}``
      • git remote -v
      • Example output:
           ipp-exercise-solutions	https://github.com/labbenchstudios/ipp-exercise-solutions.git (fetch)
           ipp-exercise-solutions	https://github.com/labbenchstudios/ipp-exercise-solutions.git (push)
        
  • Important note on pathnames!

    • The ipp-exercise-solutions (or ipp-exercise-components) path will usually be referred to as IPP_HOME

Step 5: Create and Configure a Virtual Python Environment

NOTE: This is very easy to do - it creates a separate Python execution environment and library repository specific to this course.

  • This is a common practice and very useful in keeping your different Python projects - each which likely have different dependencies - completely separate from one another

Create and Configure a Virtual Python Environment

  • Create a virtual environment for your Python development environment
    • cd IPP_HOME
    • python3 -m venv .venv
    • Done!
  • Configure your virtual environment
    • This will install the Python library dependencies you'll need for the course
    • On Windows
      • IPP_HOME/.venv/Scripts/activate
      • pip install -r requirements.txt
    • On WSL / Linux / macOS
      • source IPP_HOME/.venv/bin/activate
      • pip install -r requirements.txt

Set PYTHONPATH

NOTE: Whether running Python tests within your IDE or from the command line, you must set the PYTHONPATH environment variable in every execution environment (e.g., every terminal you launch) when attempting to run the IPP app or any of its tests from the command line. The IPP main source code and test paths are simply:

  • {IPP_HOME}
  • {IPP_HOME}/tests

To Set your PYTHONPATH:

  • Windows
    • set PYTHONPATH=IPP_HOME:IPP_HOME/tests
  • WSL, Linux, macOS
    • export PYTHONPATH=IPP_HOME:IPP_HOME/tests
  • Remember: IPP_HOME is the directory where your IPP repository exists

To exit from your Virtual Environment:

  • Simply enter the following command:
    • deactivate

Windows Example
If you're using Windows 11, and you're IPP_HOME is C:\Users\MyHome\ipp\ipp-exercise-solutions, the command to set your PYTHONPATH for this course will be:

  • set PYTHONPATH=C:\Users\MyHome\ipp\ipp-exercise-solutions:C:\Users\MyHome\ipp\ipp-exercise-solutions\tests

WSL Example
If you're using WSL and you're IPP_HOME is /mnt/d/MyHome/ipp/ipp-exercise-solutions, your export command may look similar to the following:

  • export PYTHONPATH=/mnt/d/MyHome/ipp-exercise-solutions:/mnt/d/MyHome/ipp-exercise-solutions/tests

Linux Example
If you're using WSL and you're IPP_HOME is /home/MyHome/ipp/ipp-exercise-solutions, your export command may look similar to the following:

  • export PYTHONPATH=/home/MyHome/ipp-exercise-solutions:/home/MyHome/ipp-exercise-solutions/tests

macOS Example
If you're using macOS and you're IPP_HOME is /Users/MyHome/ipp/ipp-exercise-solutions, your export command may look similar to the following:

  • export PYTHONPATH=/Users/MyHome/ipp-exercise-solutions:/Users/MyHome/ipp-exercise-solutions/tests

NOTE on using a Python virtual environment and setting PYTHONPATH: You can add your PYTHONPATH export command to the virtual environment's activate.sh or activate.bat script if you'd like. This way your PYTHONPATH environment variable will be set everytime you launch your virtual environment. The caveat is that it will overwrite any other PYTHONPATH you may have set for a different project. There are many solutions to this conundrum online for those curious.

Step 6: Select and Install an IDE (Integrated Development Environment)

NOTE 1: There are many excellent Python Integrated Development Environment (IDE) tools available - some are free, others may have a subscription or other cost. Included here are some basic guidelines on setting up your dev environment using four popular Python IDE's. Use the IDE you're most comfortable with!

NOTE 2: For this course, most (if not all) examples will be shown using VS Code running on either macOS or in Windows 11 using WSL v2 (Windows Subsystem for Linux, version 2).

Estimate

  • This process can vary in duration depending on your own computing environment, Internet download speed, etc.

Tests

  • N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Lab Module 01 - Setup

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions