Software Setup#

This page contains common instructions for downloading software to run and edit Python files.

Tip

Preface: Getting a development environment set up is easily one of the most frustrating things about being a programmer, so it’s okay if this process doesn’t go smoothly! If you run into troubles along the way, that’s totally expected. It is very common to Google (or DuckDuckGo) errors you run into while setting up an environment and try follow suggestions from other questions posted online to fix your solution. It could also help if you have a friend or instructor who is familar with how to set up developer tools.

Warning

If you are using this book as part of a course, your instructor may have differing instructions for software setup and tools used, or they might even have provided software installed on computers. Please refer to any instructions your instructor has provided for software for your course.

Instructions#

Step 1 - Install Anaconda#

Go to Anaconda’s website and install Python 3.8 for whichever operating system you own.

Once installed, you should open the Anaconda Navigator application and you will see a screen like:

Anaconda screen

Step 2 - Create Environment and Install Python Packages#

Download the environment.yaml (right-click and “Save Link As”) somewhere on your computer. This file specifies all of the requisite Python packages and their versions. The location of this file does not matter as long as you remember where you saved it.

Navigate to the Environments section on the left, and click the Import button at the bottom. Click on the folder icon, navigate to and select the environment.yaml file you downloaded earlier. In the prompt after selecting the environment specification, you should name the environment cse163. Once you have done this and created the environment, it will install all of the necessary packages.

Anaconda importing

After all the packages have been installed, you should see an environment called cse163 and if you select it, will have many packages installed. Clicking on the environment should show you something that looks like a list of Python packages:

Anaconda environment

Step 3 - Install Visual Studio Code#

Go to Visual Studio Code’s website and install the IDE for whichever operating system you own.

Once installed, you should open the Visual Studio Code application and should see a screen like below. You should click the Python link circled in red to install the VSCode Python plugins VSCode screen

Step 4 - Set Up VSCode for Python Development#

Download test.zip to whichever directory you plan to use to store homework assignments and unzip it so you have a test directory in your working directory. If you click the “Open Folder” button on the welcome page of the VSCode application and select the test directory, you should then see the following editor if you click on the main.py on the left. It is entirely expected that you might see some errors when you first open the file!

VSCode showing main.py

The first import shows up as red since VSCode is most likely not using the cse163 Anaconda environment we just set up. In the blue bar at the bottom in the above image, you should see which version of Python VSCode is currently using. Click on it and a prompt should appear for you to select, and you should find the one relating to the cse163 Anaconda environment (should be something like anaconda/envs/cse163/bin/python, but may be different based on your operating system) which is circled in red in the diagram below. Once you selected the cse163 environment, you should no longer get a warning about not being able to import geopandas if there was one earlier.

VSCode showing Python version

If you are using Windows#

If you have Windows 10, VSCode will use PowerShell as the default program when you try to run a Python program, but unfortunately this does not work with Anaconda. To fix this, open up Preferences, search for “Shell” and change the value of Terminal > Integrated > Shell: Windows to C:\Windows\System32\cmd.exe (or wherever the program for Command Prompt exists on your machine). It seems like some newer versions of VS Code don’t let you set this property directly, but rather require you to edit this thing called settings.json. If you follow the instructions above and only see an option to edit this file, do so and make it so it has the following contents:

{
    "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
}

Notice that this is the same path as above, with but with the back-slashes doubled to make it a valid escape-sequence.

Step 5 - Set Up Linter: flake8#

During this process, you may have also gotten a pop-up about selecting a linter (a program that checks your program for style errors). You should use flake8 as a linter for this class. If you missed the pop-up, that’s okay just follow these steps:

  • Open the Command Pallet (Shift+Cmd+P on Mac, Ctrl+Shift+P on Windows/Linux)

  • Type >Python: Select Linter and select flake8

  • You might also need to enable the linter by typing >Python: Enable Linter and selecting on

It’s intended that there are linter errors in the provided code so you can see that it is working. Don’t fix these yet.

Step 6 - Verify Everything Works#

  • With main.py open, right click in the main editor window and select “Run Python File in Terminal”. This will open up a window at the bottom and after a second, should print out

    Main runs
    Foo runs
    

    if you have set up the environment correctly. It might also print out a warning if it looks like you are using the wrong version of Python.

  • There should be multiple style warnings from flake8 (seen with the error count at the bottom, or the red squiggly lines in the editor) from the fact that we used semi-colons to end lines 18 and 19 and had imports that were unused. For this exercise, you should leave the unused imports in the code but you should delete those semi-colons and save the file to rerun flake8 and verify those errors should go away.

Once you have done this, you now have a Python environment that runs the code we will need for this class as well as runs a linter to verify your solution follows good style. If either of these two steps above don’t work, please post on the message board, come to office hours, or try to Google around to see if you can get it working on your own!

Frequently Asked Questions (FAQ)#