Anaconda 3

Anaconda is a tool that simplifies Python package management and deployment. In this course, we will be using Anaconda 3 as our all-in one system setup for local Python development.

Install Anaconda 3

Already have Anaconda?

If you already have Anaconda installed, skip ahead to the Python Environment section.

Go to Anaconda’s website and download and run the installer for your operating system. The download is somewhat large, around 700MB, so please be patient! Likewise, installing Anaconda may take a while, depending on your computer and internet connection. It is normal for it to take a few minutes!

Ubuntu Users

If you are using Ubuntu, the downloaded file will be a script named similarly to Anaconda3-2023.09-0-Linux-x86_64.sh. Install Anaconda by navigating to the file in the terminal and run the following commands:

  • chmod +x name_of_your_anaconda_file.sh
  • ./name_of_your_anaconda_file.sh

Follow the prompted instructions. Once finished, you can open Anaconda Navigator by typing anaconda-navigator in your terminal.

Mac Users

If you are using Mac, you have the option of downloading the “Apple Silicon” version or the “Intel Chip” version. To determine which version you have, open the About This Mac window by clicking the Apple icon in the top left corner of your screen, and then click About This Mac. In the “Chip” section, if you see “Apple Mx” (where x is some number), you have the “Apple Silicon” version. If you see anything else, you have the “Intel Chip” version.

Either way, you should download the “Graphical Installer” version for the relevant chip version.

Python Environment

Python environments are self-contained Python installations meant to limit version conflicts and dependencies between different Python projects. It is fairly common to create a new environment whenever you work on a different project. As a result, we’ll create an environment specific for this course.

Info

Some web browsers might automatically save the yaml file as a .txt file. Please rename the file to have the .yaml extension. The file’s full name should be 160environment.yaml.

  1. Download the 160environment.yaml file, which specifies all requisite Python packages (and their respective versions) we’ll be using in this course.
  2. Open Anaconda Navigator; it may take a few moments to load.
  3. Navigate to the Environments section of Anaconda Navigator, click Import at the bottom
  4. Click on the folder icon next to “Local drive” and select the 160environment.yaml file from your downloads folder (or wherever you downloaded that file to).
  5. Replace the text in the “New environment name” with “cse160”.
  6. Click import. Depending on your computer and internet, this may take a long time to complete. It’s worth taking a break, getting some coffee, and coming back a bit later.

Python Environment in Anaconda

Visual Studio Code

Visual Studio Code (VSCode) is a popular text editor that many developers use for a number of different programming languages. While Python can be programmed in various different tools, we will be using VSCode as our main development tool in this course.

Download VSCode

  1. Download and install VSCode according to your computer’s operating system.

Tip

If you are on a Mac and get a warning dialog about being unable to install an app from an unidentified developer, you can get around it by right-clicking the installation file and clicking Open.

  1. Once the home screen has loaded, install Python and flake8 plugins by clicking on the Extensions icon (a collection of 4 squares) on the left navigation pane, and installing the Python plugin and flake8 plugins by Microsoft.

Visual Studio Code Python plugin Visual Studio Code flake8 plugin

Setting Up VSCode

  1. Download test.py and open it in VSCode: File | Open and select test.py.
  2. Navigate to the Command Pallet from Help | Show All Commands, type in Python: Select Interpreter and hit Enter.
  3. Select the cse160 Anaconda environment we created earlier, which should have a path similar to anaconda3/envs/cse160/bin/python.
Additional Steps for Windows
  1. If you are using Windows, you must change the default program that Windows uses to run Python files. Navigate to the Command Pallet again, type in Open User Settings (JSON), and hit Enter.

  2. Add in this line immediately after the opening curly brace (that’s the one that looks like this: {): "terminal.integrated.defaultProfile.windows": "Command Prompt",

(Don’t miss the comma at the end!)

  1. Click File | Save. Finally, quit and reopen VSCode for changes to take affect.
Additonal Note for macos
  • If VSCode prompts you with a question “It looks like you’re using a conda environment?” Accept the prompt.

Bonus setup step: * VSCode doesn’t, by default, enable auto save. If you would like to have your files saved automatically as you edit then, go to File and then click on “Auto Save” (it’s near the bottom of the menu).

Select cse160 environment

Sanity Checking VSCode Setup

You can check that everything is set up correctly by test.py by clicking the Run button in the upper right-hand corner.

Run program

If everything runs correctly you should see the following output in the terminal at the bottom:

Main runs
Foo runs
Bar runs

You should also see a number of red squiggly lines in VSCode (warnings from flake8, the plugin we installed earlier which checks python files for style conventions) since test.py has some things that break style conventions in Python (unused import statement and semicolons). These can also be seen by clicking the Problems tab near the bottom of VSCode.

You may ignore these “errors” for now, but for future homework assignments, you will be expected to fix all flake8 errors and warnings.

Warning

It is possible to run Python programs without fixing all flake8 errors, however, you will lose points on future assignments if you do not fix all flake8 errors.

Flake8 Errors