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, scroll down to the bottom, and download and run the installer for your operating system. Once installed, open the Anaconda Navigator application and you should see the home screen:

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.

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.

  1. Download our 160environment.yaml file, which specifies all requisite Python packages (and their respective versions) we’ll be using in this course.
  2. Navigate to the Environments section of Anaconda Navigator, click Import at the bottom
  3. 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).
  4. Replace the text in the “New environment name” with “cse160”.
  5. Click import.

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.
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 between the curly braces: "terminal.integrated.defaultProfile.windows": "Command Prompt"

  3. 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.

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 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). You may ignore these for now, but for future homework assignments, you will be expected to fix all flake8 errors.

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