Psychology 9040B FW24
  • Schedule
  • Syllabus
  • Resources
  • Exercises
  • OWL

On this page

  • MacOS, Windows, or Linux?
  • Python
  • Code Editor
  • Git/GitHub
  • Check your setup

Set up your computer

MacOS, Windows, or Linux?

Yes.

Everything we do in this course you can do using a computer that runs MacOS, or Windows, or Linux. Personally I am most familiar with MacOS and Linux.

Python

We will be using Python in this course.

  • download and install Python

Code Editor

Python code lives in plain text files that by convention have a .py extension, and you can view and edit them in any editor you want. There are many to choose from. I use Visual Studio Code which is free and available on MacOS, Windows, and Linux. You can use whatever you wish. In class I will be using Visual Studio Code, and I will show you how to use some of its more useful features for Python programming and data analysis.

  • download and install Visual Studio Code

Git/GitHub

We will be covering code versioning using Git and GitHub, so you should:

  • download and install Git on your computer
  • sign up for a (free) GitHub account

Check your setup

Assuming you have installed Python and VSCode:

  1. create a new folder somewhere on your computer’s file system and name it Psych_9040
  2. launch VSCode
  3. in the welcome screen there is an item under “Start” called “Open Folder …” — click it and navigate to the Psych_9040 folder you created in step 1 above, and select it
  4. now click on “New File …” to create a new empty file, select “Text File” from the dropdown menu
  5. In the VSCode “File” menu select “Save” and name the file hello.py; VSCode may ask you if you want to install the Python extension, click Yes
  6. If you didn’t get asked about installing the Python extension, do it manually: type CMD-Shift-P (MacOS) or CTRL-Shift-P (Windows/Linux) to launch the Command Palette and enter Extensions: Install Extensions and select the item from the dropdown menu by clicking it with the mouse or by typing Enter/Return; the Extension browser will have opened as a column on the left hand side of the VSCode window. At the top there is an empty text entry field. Type Python; click “Install” on the one called “Python” (Python extension for Visual Studio Code) from Microsoft
  7. type the following in your hello.py file:
import numpy as np

x = np.array ([2, 3, 5, 7, 11, 13, 17, 19, 23, 29])
y = np.sum(x)
print(f"the sum of {x} is {y}")
  1. launch the Command Palette and type in Python: Create Environment and select that item in the dropdown list

  2. select the “Venv” option to create a .venv virtual environment in the current workspace

  3. select your preferred Python interpreter from the dropdown list

  4. bring up the Command Palette again and type Terminal: Create New Terminal and select it; (note: if you are on Windows, click the down-arrow next to the + and select “Select Default Profile” and then select “Command Prompt”)… then close the terminal and re-open it via the Command Palette

  5. in the Terminal that opens up, type pip install numpy and then Return/Enter

  6. now type python hello.py and Return/Enter

You should see the following output in the Terminal:

the sum of [ 2  3  5  7 11 13 17 19 23 29] is 129