# 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](https://code.visualstudio.com/) if you haven't already. 2. Download the correct version of Python (3.10.6) [here](https://www.python.org/downloads/release/python-3106/). Do this even if you have another version of Python installed on your machine. :::warning **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: - [requirements.txt file](https://drive.google.com/file/d/14krDZ2qKeIwkhvJUjCEOek3OFPpcDbbw/view?usp=sharing) <!-- - [m1/m2 Mac](https://drive.google.com/file/d/1DW7crninjQ32IG3stocJTyOwsT5B5r-J/view?usp=sharing) - [Intel Mac](https://drive.google.com/file/d/1gUxM1ukQit2tsB_5XoUzxJRW9hL9nZv5/view?usp=sharing) - [Windows](https://drive.google.com/file/d/13bAz4lPucYXKTECZygeA7n_lbEHmh8Se/view?usp=sharing) --> 3. 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 4. In a VSCode terminal, navigate to the new directory: `cd ~/Desktop/cs410` ::: spoiler Can't find the VSCode terminal? Go to the menu bar -> select `Terminal` -> select `New Terminal`. ::: 5. 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) ::: warning **Note:** Make sure you are in the cs410 directory when running the above commands ::: 6. 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` ::: spoiler Error: running scripts disabled on system If you are running into execution policy restrictions (typically on Windows), follow this [Stack Overflow post](https://stackoverflow.com/questions/67150436/cannot-be-loaded-because-running-scripts-is-disabled-on-this-system-for-more-in) to resolve the issue. ::: Your terminal should look like this when it is activated correctly: ![image](https://hackmd.io/_uploads/B1wH1AE3C.png) 7. 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 8. 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` ::: spoiler 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](https://visualstudio.microsoft.com/visual-cpp-build-tools/ ). 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!](https://hackmd.io/45NLg5CbSj6So9GhM_p3Iw?view) 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: ![Screenshot 2024-08-06 at 11.06.01 PM](https://hackmd.io/_uploads/r18sNDxcR.png) 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](https://archive.mantidproject.org/How_to_run_Pylint.html). ::: danger **Remember:** While Pylint allows you to disable seeing violations, **DO NOT DO DISABLE WARNINGS** for your CS410 work, or you will risk point deductions. :::