Try โ€‚โ€‰HackMD

CS 410 Python Installation & Setup

Overview

The course uses Python as our language. As software library installation and management can often be tricky, Python supports virtual environments which collect and isolate a set of packages and their versions. CSCI 410 has its own virtual environment to reduce configuration issues. Assignment 0 tasks you with setting up this environment locally.

Software and Tools

  • Python Version: Python 3.10.6. As our autograder exclusively runs 3.10.6, we will not provide support for other versions of Python.
  • Editor: Visual Studio Code (VSCode), a free cross-platform editor with debugging support.

Virtual Environment Setup on a Personal Machine

Preparation

  1. Download VSCode if you haven't already.
  2. Download the correct version of Python (3.10.6) here. Do this even if you have another version of Python installed on your machine.

IMPORTANT: For Windows users, when you first click on the .exe installer, you should make sure the Add python.exe to PATH box is checked BEFORE you click "Install Now".

Creating the Virtual Environment

  1. Create a directory for the course: cd ~/Desktop && mkdir cs410
  2. Download the requirements.txt file below:
  1. Put the requirements.txt you just downloaded in your new CS410 directory.

    Store project files in relation to the virtual environment like so:

    cs410/

    |โ€“- cs410env/
    |โ€“- assignment-1
    |โ€“- assignment-2
    |โ€“- โ€ฆ
    |โ€“- requirements.txt

  2. In a VSCode terminal, navigate to the new directory: cd ~/Desktop/cs410

Can't find the VSCode terminal?

Go to the menu bar -> select Terminal -> select New Terminal.

  1. Create a virtual environment:
  • Run python3.10 -m venv cs410_env (Mac users)
  • If the above doesn't work, try py -3.10 -m venv cs410_env (Windows users)

Note: Make sure you are in the cs410 directory when running the above commands

  1. Activate your new environment:
  • For all Mac users: source cs410_env/bin/activate
  • For Windows users: cs410_env\Scripts\activate
  • For Linux users: source cs410_env/bin/activate.csh
Error: running scripts disabled on system

If you are running into execution policy restrictions (typically on Windows), follow this Stack Overflow post to resolve the issue.

Your terminal should look like this when it is activated correctly:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More โ†’

  1. Once you have activated your environment, check that the Python version inside the environment is correct:
  • run python -v - towards the end of the terminal output you should see "Python 3.10"
  • type exit() to return to the normal command line
  1. Once the environment is activated, run pip install -r requirements.txt

Before Every Assignment:

Activate the Environment

  • For all Mac users: source cs410_env/bin/activate
  • For Windows users: cs410_env\Scripts\activate
If you encounter issues on Windows
  • If you encounter ERROR: Could not find C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe, download Microsoft Build Tools for Visual Studio. During installation, make sure to select the "Desktop Development with C++" workload
  • If you encounter ModuleNotFoundError: No module named 'distutils.msvccompiler', ensure you have Python version 3.10.6 installed
  • For Linux users: source cs410_env/bin/activate.csh

Deactiving the Environment

To deactivate the environment, use the following terminal commands:

  • For Mac M1/M2 users: conda deactivate
  • For all other Mac users deactivate
  • For Windows users: deactivate

Enabling Pylint

Through the shell script in the previous step, we've already installed PEP8 library, the industry standard Python style guide, for you. Next, you should activate Pylint, a linting tool that automatically checks for semantic and stylistic issues. Linting makes it easier to spot subtle errors and effortlessly follow the CS410 Style Guide!

Enable Pylint by following these steps:

  1. In VSCode, click on the Extensions icon on the left sidebar (it looks like four squares) or press Ctrl+Shift+X to open the Extensions tab.
  2. Search for Pylint and install it.
  3. Double check that the extension is enabled.

The extension should now look like this:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More โ†’

Once installed, Pylint will highlight errors in your VSCode file with squiggly lines, indicating PEP8 violations. Hover over an underlined issue to see the details.

To get a comprehensive list of all errors and warnings for a specific file, run the command pylint fileName.py in your terminal. This will print the style errors in your terminal. For more information on using Pylint, visit this guide.

Remember: While Pylint allows you to disable seeing violations, DO NOT DO DISABLE WARNINGS for your CS410 work, or you will risk point deductions.