Installing and Using the Software


While this is not a programming course, you will do a fair bit of coding, far more than in CSCI2243. We will use the Python programming language.   From Python itself, I want you to be able to write functions, use simple looping and branching, and manipulate one-dimensional lists.  (No need to worry about tuples, dictionaries, or object-oriented stuff.)  You will also install the scientific computing package numpy and the plotting package matplotlib (which requires numpy).

The following installation procedures have worked for almost all students. I have tried them on a number of machines, including an ancient Windows laptop, but some students invariably have issues with this, usually because their computers are configured somewhat differently from the norm.  Please try to do this installation as early as you can, and let me know as soon as possible if you encounter any problems.

Python 3

First check to see if you have Python 3 already installed on your computer.  If you do, you can skip this step.  If you are using a Macintosh, you should see a folder in your Applications folder named Python 3.x (on my machine, x=7, but this does not matter so much).  If you are using a Windows computer, you will see  Python 3.x in your list of programs.

If you don't have Python 3, go to www.python.org/downloads/   and click on the link to Download Python 3.7.2.  The site should detect automatically what operating system you are using, and download the appropriate installer file, which has the extension .pkg on MacOS, and .exe on Windows. (There is a little quirk in Windows 10:  this worked just as described if I used the built-in Microsoft Edge browser, but I had to hunt around a bit for the correct installer package if I used a different browser.)  Launch the installer file and follow the defaults.  Also, make a note of the directory in which Python 3 is installed.

Advice for Mac users:  If you have a Mac that shipped with a pre-installed version of Python, I recommend that you do this installation anyway---it does not take up a lot of extra space, and this seems to make the next step go more smoothly.)

On MacOS:  Go to Applications, then the Utilities folder, and open up the Terminal application.  Type

python

at the prompt.  If it tells you that you are using Python 3.7. something,  go to the 'matplotlib and numpy' step.  If it tells you Python 2.something, try typing

python3

instead. If you see something along the lines of

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)

proceed to the ' matplotlib and numpy ' step below.  (I have both Python 2 and Python 3 on my computer; yours may be configured differently.)  If this still doesn't work, come talk to me or the TAs for help.

On Windows:  You first need to find out where the python executable is stored on your computer, if you did not make a note of this when you installed Python 3.  Go to IDLE, and in the Python Shell type

import os
import sys
os.path.dirname(sys.executable)


On my computer, I got as a response the following ridiculously long path name:

'C:\\Users\\straubin\\AppData\\Local\\Programs\\Python\\Python37-32'

Open the Command Prompt, and navigate to this folder (or whichever path name you got in the previous step).  Do this by typing (if you are me):

cd C:/User/straubin/AppData/Local/Programs/Python/Python37-32

Then try typing

python

or 

python3

When you get a response that informs you that you are using Python, version 3.something, you've come to the right place.

matplotlib and numpy


You will need to install some packages for performing scientific computing and visualizing data,  The instructions are slightly different, depending on the operating system.
 If you've gotten this far, quit the Python Shell in Terminal or in Command Prompt by typing

quit()

Then type either

python -m pip install numpy

or 
python3 -m pip install numpy

depending on which command you used to launch Python in the previous step.  Hope you don't get an error message.  Then continue with

python -m pip install matplotlib

Test the Installation Start up IDLE.  Type these three lines at the successive prompts.

from pylab import *
plot(range(5),sqrt(range(5)))
show()


It may take a moment for the prompt to return after the first line, but there should be no error messages.  The second line should result in a message like

[<matplotlib.lines.Line2D object at 0x96a24d0>]

Finally, the third line should display a very crude graph of the square root function.

Using matplotlib

There are several different ways to use matplotlib. The procedure that I follow is not always the recommended one, because of the risk of conflicting names from different packages, but I find that it works reasonably well and makes most things simpler. 

Typing

from pylab import *

imports  core capabilities of NumPy along with the plotting libraries for matplotlib.  The stuff from NumPy replaces much of the math library from standard Python.  For example, you might note that in the code fragment above, we used the function sqrt without the usual invocation of import math and a call to math.sqrt.  Pay particular attention to what happens with random number generation, which we do a lot of in this course.  The pylab import provides functions random and randint, just as in the standard package random. However, a call to randint(i,j) returns a random integer in the set {i,..,j-1}, and not in {i,...,j} as in the standard Python package.

During the first week of class I will give a detailed demo of the software.  There are links to the documentation on the course website.