All the CS5670 projects will be purely python-based. In this tutorial, we will guide you through setting up a python virtual environment called cs5670_python_env on your computer. cs5670_python_env takes care of the dependent python packages for you, and will be used over the semester. Please make sure your code is executable in this environment before submission.

Install python2

As you may have heard, there are two major python versions, python2 v.s. python3. Although the syntax difference might be small, they are not fully compatible with each other. For this course, we will be adopting python2 as we did in previous years.

Below is how to install python2 if you don't have it on your operating system.

Mac:

python2 is preinstalled on Mac, so you don’t have to worry about it

Ubuntu:

Older ubuntus (<18.04) are shipped with python2 and you don’t have to do anything. For ubuntu 18.04, python3 is preinstalled as default; thus to use python2, launch a terminal and type

sudo apt install python python-tk

Windows:

Download python2 via this link and install it on your computer. Suppose you've installed python2 at location C:\python2\; then you would need to add C:\python2\ and C:\python2\Scripts to your system environment variable, Path.

Suggestion:

If you would like a Unix-like terminal on windows, we recommend you to try Cmder. When you use Cmder, note especially that you can't switch between different disk drives using cd command. For example, if you are at C drive, and you would like to go to D drive, simply type d: instead of cd d:.

Check whether python2 works properly

Launch a terminal on your computer and type

python --version

If you see 2.x.x, that means python2 is successfully installed.

Set up cs5670_python_env

Once you have python2 installed on your computer, launch a terminal and switch to the directory in which you would like to put the cs5670_python_env.

Mac and Ubuntu:

pip install virtualenv

virtualenv --system-site-packages cs5670_python_env

source cs5670_python_env/bin/activate

Windows:

pip install virtualenv

virtualenv --system-site-packages cs5670_python_env

cs5670_python_env/Scripts/activate

You should now see a cs5670_python_env in the command prompt, which indicates that you are inside the cs5670_python_env environment.

Work with cs5670_python_env

In this section, we explain the basic workflow of interacting with cs5670_python_env. Take the first project, Hybird Images, as an example.

First, you need to clone the skeleton code from github repo.

git clone https://github.com/cornelltechcs5670/Cornell-CS5670-2020.git

Second, since the file 'Cornell-CS5670-2020/Project1_Hybrid_Images/requiresment.txt' specifies the dependent packages for this project, you need to install them inside cs5670_python_env. Remember to substitute the place holder {full path to} with your specific directory path.

Mac and Ubuntu:

source {full path to}/cs5670_python_env/bin/activate

pip install --force-reinstall -r Cornell-CS5670-2020/Project1_Hybrid_Images/requirements.txt

Windows:

{full path to}/cs5670_python_env/Scripts/activate

pip install --force-reinstall -r Cornell-CS5670-2020/Project1_Hybrid_Images/requirements.txt

Third, you are now ready to work with the skeleten code. In the future, every time you would like to execute your scripts inside cs5670_python_env, activate it first in the terminal via the following command. Remember to substitute the place holder {full path to} with your specific directory path.

Mac and Ubuntu:

source {full path to}/cs5670_python_env/bin/activate

Windows:

{full path to}/cs5670_python_env/Scripts/activate

The command prompt will have a 'cs5670_python_env' saying that you are inside the environment. Launch your python scripts in cs5670_python_env just as how you normally do in the terminal. When you don’t want to use cs5670_python_env, deactivate it,

deactivate

Python Code Style

As you know, python is a programming language that heavily depends on indentaion and line endings. To be consistent with the provided skeleton code, make sure to customize your code editor such that python statements are indented by four spaces, and the line ending charater is set to be \n.

Lab Machines

In case you would like to use the lab machines in the master studio, we've set up python2, cmder, cs5670_python_env at D:\cs5670 on those machines.