- Start here!
- Set up your computer
Try this 10-minute tutorial. When it
tutorial and press Enter to start.
Set up your computer
This is our recommended way to install Python on your system.
- Please download the Anaconda installer. We recommend Python 3.
Install for me only
- By default, Anaconda will prepend itself to your PATH – leave this as is
- When Anaconda has finished installing, open a terminal (Linux, OSX), or the Anaconda Prompt (Windows)
conda update conda, hit enter, and then type "y" (and hit enter)
conda update anaconda, hit enter, and then type "y" (and hit enter)
Run the Jupyter Notebook
With Jupyter, you intersperse code, output, explanatory text, and figures in one big file called a "notebook." Notebooks are a convenient format to explore a language and to share examples of code.
- To run a notebook, open the Terminal (Linux, OSX) or Anaconda Prompt (Windows) and type
- The notebook will open a new tab in your default browser. Do not close the terminal, as this will also shutdown the notebook.
- When it has loaded, click on "New" (at the top right) and then "Python3" to create a new notebook.
Python 2 vs Python 3
Python 3 (released in 2008) is the newest version of Python, and most features have not changed. Most packages have been updated to Python 3 by now (2016). So, if your lab does not have a preference, I recommend using Python 3.
There are a couple key differences for novice programmers:
- In Python 2, you can print with
print(42). In Python 3, you need to use parentheses, as in
In Python 2, division of two integers like
5/2will evaluate to
2. (Python will drop the remainder if both numbers are integers.) Python 3 does exact division ('2.5', in this example). If you use Python 2 and do not want this behavior, add this line at the top of each program:
from __future__ import division.
Text editors and IDEs
For creating large projects in Python, we recommend using a text editor in combination with the Jupyter notebook. Popular choices include:
For even larger projects, a well-engineered IDE (Interactive Development Environment) may be better than a text editor. Typically, IDEs include drag-and-drop support for debugging and refactoring. Popular choices include:
Python for Social Sciences
This is a free online book by Jean Mark Gawron. It's free and online at this link.