CSE 160 Setup Guide
Preface: Getting a development environment setup 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, please make sure to post on the message board, come to office hours, or just Google around to see if you can solve the problem on your own!
Go through the steps below to setup your local enviroment:
-
Contents:
- Step 1: Install Anaconda 3
- Step 2: Create Enviroment and Install Python Packages
- Step 3: Install Visual Studio Code
- Step 4: Set Up VSCode for Python Development
- Step 5: Setup Linter: flake8
- Step 6: Verify Everything Works
Install Anaconda 3
Already Have Anaconda?
If you already have Anaconda 3 installed with a version of Python 3.7 or later, you should move on to the next step. If you have Anaconda 3 installed, but with a version of python before version 3.7, you should open up terminal/command prompt and run the commands:
conda update conda
conda install python=3.7
- You may then skip this step after you have installed a version of python 3.7 or later.
Installing Anaconda 3
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:
![Sample picture of what you should see in anaconda](./anaconda.png)
If you are using Ubuntu, the downloaded file will be a script named similar to this:
Anaconda3-2020.07-Linux-x86_64.sh
To install Anaconda, navigate to the file in terminal and run the following commands (replace with the actual name of your file):
chmod +x <Anaconda3-2020.07-Linux-x86_64.sh>
./<Anaconda3-2020.07-Linux-x86_64.sh>
Then follow the instructions prompted. You can then open the navigator by typing
anaconda-navigator
in your terminal.
Create Enviroment and Install Python Packages
Download the 160environment.yaml 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.
Note: We noticed that if you download the yaml file for cse160 env using Safari on MacOS, it might automatically add a .txt suffix to the file. Please make sure that the file name ends with .yaml if this is causing you trouble.
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 160environment.yaml
file you downloaded earlier. In the prompt after selecting the environment specification, you should name the environment cse160. Once you have done this and created the environment, it will install all of the necessary packages.
![Sample picture of what you should see in anaconda while setting up the env](./env.png)
After all the packages have been installed, you should see an environment called cse160 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:
![Sample picture of what you should see in anaconda after setting up the env](./160env.png)
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. If you have a mac, you might get a prompt like this when you try to open Visual Studio:
![Sample picture of what you may see if your computer things VSCode is sus](./vscodesus.png)
If that's the case, navigate to your Mac's System Preferences > Security & Privacy. In the General tab, navigate and click Open Anyway button next to ("Visual Studio Code" was blocked from use because it is not from an identified source).
Once you open the Visual Studio Code application, you should see a screen like below. You should click the Python link circled in red to install the VSCode Python plugins
![Sample picture of where to click to setup python in vs code. Left of center of the screen.](./pythonlink.png)
Set Up VSCode for Python Development
Download test.py to whichever directory you plan to use to store homework assignments. If you click "File > Open File", you should be able to navigate to and open the test.py
file you downloaded earlier. After opening the file, you should then see something similiar to the following editor. It is entirely expected that you might see some errors when you first open the file!
![Sample picture of what you will see once the code has been opened in vscode](./testcode.png)
Note: the bottom bar of your editor should be purple. If you are seeing a blue bar, then it is likely you opened the folder instead of opening the indivdual file. You should open the file on it's own.
The second import shows up as red since VSCode is most likely not using the cse160
Anaconda environment we just set up. In the purple 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 cse160 Anaconda environment (should be something like anaconda/envs/cse160/bin/python, but may be different based on your operating system) like the second option in the diagram below. Once you select the cse160 environment, you should no longer get a warning about not being able to import numpy if there was one earlier.
![Sample of the drop down menu to select the correct enviroment.](./select160.png)
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 File->Preferences->Settings, 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).
For some newer versions of VS Code don't let you set this property directly, but rather require you to edit the value through 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, but with the back-slashes doubled to make it a path readable by VSCode's settings program.
Setup 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 selectflake8
- You might also need to enable the linter by typing
>Python: Enable Linter and selecting on
You can double check that you have flake8 configured to work for all of your Python code in VSCode by selecting: (On Windows: File->Preferences->Settings, on Mac: Code->Preferences->Settings) and making sure the following is set:
![Sample of what setting up flake8 should look like.](./flake.png)
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.
Verify Everything Works
With test.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
- Bar runs
- 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 "Problems" count at the bottom, or the red squiggly lines in the editor) from the fact that we used semi-colons to end lines 10, 11, 15, 19 and 20 and had imports that were unused. For this exercise, you should leave the unused imports in the code but you should delete those semicolons and save the file to rerunflake8
and verify those errors should go away.
If you are not getting any style warnings from flake8, follow the steps below
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!
If you do not have stlye warnings from flake8, try the following:
After you have run your python program, you should have access to a terminal at the bottom portion of your screen.
From here, you will have to type in a command into the terminal based on the operating system you are using:
- If you use Windows, type:
where flake8
- If you use Mac or Linux, type:
which flake8
Both of these commands should spit out a path to a file. This output is the proper path to the flake8 program. Copy this path since we will need it in a minute.
Open up the Preferences of VSCode and search for "flake8
". There is a setting called Python > Linting: Flake8Path
that probably has the value flake8
currently. Delete that value and paste the output path from the last command here. Once you save, it should hopefully work now!