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, 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!
Table of Contents
If you already have Anaconda 3 installed with a version of Python before 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 successfully installed Python 3.7.
Go to Anaconda's website and install
Python 3.7 for whichever operating system you own.
Once installed, you should open the Anaconda Navigator application and you will see a screen like:
environment.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.
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.
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:
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
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!
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.
If you are using WindowsIf 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).
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:
>Python: Select Linterand select
>Python: Enable Linterand selecting
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.
main.pyopen, 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
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.
Main runs Foo runs
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
flake8and 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!
Note: This section will be updated throughout the quarter (especially at the beginning), so you should check back frequently if you run into problems!
I can't run anything in the terminal in VSCode, what do I do?
It's likely that your program crashed due to an error interpreting your code. If you wrote the incorrect syntax, Python crashes but does not exit which will cause errors if you try clicking the "Run in Terminal" button again. To fix this, you must exit the Python interpreter by clicking on the terminal prompt and typing in
Ctrl-D to exit. Once you do this, you should be able to re-run your program.
Tip: I commonly only use "Run in Terminal" only once to generate the proper command, and then I will always just use the terminal to run by pressing the "up" key to get the previous command. This way, you won't forget to exit the Python shell since you actually have to work with that shell. This is not necessary, but something that has helped me avoid this bug.
If you are completely unable to get the environment setup, we have a set of alternate instructions that can be found here.