Programming Assignment 0

Introduction

This assignment gets you started with the basic tools you will need to complete all of your programming assignments. This project will

Problem Description

You are a CS 3642 student who needs to install Python, configure it for command line use, and learn how to use a programmer's text editor to create and edit Python source code.

Solution Description

Part 1: Python

On Unix/BASH you can create both of these directories at once with

$ mkdir -p cs3642/pa0

Windows uses the same commands for directory navigation and creation, cd and mkdir, but Windows's mkdir command doesn't have the -p option.

Note: the $ is the command prompt on most Unix shells and Windows 10's Ubuntu BASH shell (would be something like C:\> in Windows cmd), the text after it is what you enter.

$ python3 --version > pa0-output.txt

> redirects the output of a program, in this case to the pa0-output.txt file. Important note: if the line above doesn't write your Python version to the pa0-output.txt file then replace the > with 2> and try again. Some versions of Python, such as the one installed by Anaconda and miniconda, write the Python version to stderr instead of stdout. > redirects stdout and 2> redirects stderr. For more informaiton, this blog post has a nice discussion of the file descriptors stdin, stdout and stderr.

print("\u004D\u0065\u006F\u0077 " * 9)
print("...")
print("\u004D\u0065\u006F\u0077\u0021")

Part 2: Libraries

AI software development, like most software development, relies on many packages outside the Python standard library. In this part you will:

Follow these steps. If you're not sure what's going on, see the Background section below.

  1. Create a virtual environment. In your pa0 directory, execute:
python3 -m venv venv
  1. Activate your virtual environment.

On a Unix-like OS (e.g., Linux or macOS):

source venv/bin/activate

or in Windows PowerShell:

venv\bin\activate.ps1
  1. Install essential and popular AI libraries. First, download this requirements.txt file to your pa0 directory. Then:
python3 -m pip install -r requirements.txt
  1. List the installed packages in your venv and add it to the assignment output report.
python3 -m pip freeze >> pa0-output.txt

You'll notice that the output above differs from the requirements.txt file.

Background

Packages

There are two meanings for "package" in Python:

  1. Subdirectories into which modules are organized. See Python's module documentation for details.
  2. A distribution of 3rd-party software, e.g., Python modules and supporting files, native code, etc.

Here we discuss the second meaning.

Installing Packages

The pip3 command downloads and installs packages.

You can invoke pip3 in two ways, for example, to install ipython:

python3 -m pip install ipython

or

pip3 install ipython

Virtual Environments

Different Python projects may use different versions of the same package. To avoid conflicts, use virtual environments.

In the root directory of your Python project, create your virtual environment with:

python3 -m venv venv

This creates a virtual environment in the venv subdirectory of your project root directory. Activate the virtual environment on macOS or Linux with:

source venv/bin/activate

or in Windows PowerShell (if this doesn't work, try Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser. See venv docs for details.):

venv\bin\activate.ps1

Deactivate a virtual environment with (macOS, Linux, or Windows):

deactivate

Direnv

To make activating and deactivating easier, I recommend using direnv.

Put this content into a file called .envrc in your project root directory.

export VIRTUAL_ENV=venv
layout python3

Then give direnv permission to use the .envrc file to activate environments by entering the following shell command in your project root directory:

direnv allow .

No whenever you enter this directory, or a subdirectory within it, your Python venv will be activated, and whenever your enter a parent directory, it will be deactivated.

Turn-in Procedure

Submit your pa0-output.txt file to the assignment on D2L.