Installing Python???cs109/content
All the labs and assignments in this course are Python-based. This page provides information about configuring Python on your machine.
Step 0The IPython notebook runs in the browser, and works best in Google Chrome. You probably want to use Chrome for assignments in this course
The Anaconda Python distribution is an easily-installable bundle of Python and many of the libraries used throughout this class. Unless you have a good reason not to, we recommend that you use Anaconda.
Download theappropriate versionof Anaconda
Follow the instructions on that page to run the installer
Test it out: open a terminal window, and typepython, you should see something like
Python 2.7.5 |Anaconda 1.6.1 (x86_64)| (default, Jun 28 2013, 22:20:13)
IfAnacondadoesn't appear on the first line, you are using a different version of Python. See the troubleshooting section below.
Test out the IPython notebook: open a Terminal window, and typeipython notebook. A new browser window should pop up.
ClickNew Notebookto create a new notebook file
Update IPython to the newest version by typingconda update ipythonat the command line
Download theappropriate versionof Anaconda
Follow the instructions on that page to run the installer. This will create a directory atC:\Anaconda
Test it out: start the Anaconda launcher, which you can find inC:\Anacondaor, in the Start menu. Start the IPython notebook. A new browser window should open.
ClickNew Notebook, which should open a new page.
Update IPython to the newest version by opening a command prompt, and typingconda update ipython
Installing additional libraries
Anaconda includes most of the libraries we will use in this course, but you will need to install a few extra ones:
The recommended way to install these packages is to runpip install BeautifulSoup mrjob pattern seabornon the command line. If this doesn't work, you can download the source code, and runpython setup.py installfrom the source code directory. On Unix machines, either of these commands may requiresudo(i.e.sudo pip install...orsudo python)
To view an IPython notebook, you must first start the IPython notebook server in the directory where the file lives. Simply navigate to this directory at the command prompt, and typeipython notebook. This will open a browser window, listing all theipynbfiles in that directory.
ProblemWhen you start python, you don't see a line likePython 2.7.5 |Anaconda 1.6.1 (x86_64)|. You are using a Mac or Linux computer
ReasonYou are most likely running a different version of Python, and need to modify your Path (the list of directories your computer looks through to find programs).
SolutionFind a file like.bash_profile,.bashrc, or.profile. Open the file in a text editor, and add a line at this line at the end:export PATH="$HOME/anaconda/bin:$PATH". Close the file, open a new terminal window, typesource ~/.profile(or whatever file you just edited). Typewhich python-- you should see a path that points to the anaconda directory. If so, runningpythonshould load the proper version
If this doesn't work (typingwhich pythondoesn't point to anaconda), you might be using a different shell. Typeecho $SHELL. If this isn'tbash, you need to edit a different startup file (for example, if ifecho $SHELLgives$csh, you need to edit your.cshrcfile. The syntax for this file is slightly different:set PATH = ($HOME/anaconda/bin $PATH)
ProblemYou are running the right version of python (see above item), but are unable to import numpy.
ReasonYou are probably loading a different copy of numpy that is incompatible with Anaconda
SolutionSee the above item to find your.bash_profile,.profile, or.bashrcfile. Open it, and add the lineunset PYTHONPATHat the end. Close the file, open a new terminal window, typesource ~/.profile(or whatever file you just edited), and try again.
ProblemUnder Windows, you receive an error message similar to the following: "'pip' is not recognized as an internal or external command, operable program or batch file."
ReasonThe correct Anaconda paths might not be present in your PATH variable, or Anaconda might not have installed correctly.
SolutionEnsure the Anaconda directories to your path environment variable ("\Anaconda" and "\Anaconda\Scripts"). Seethis pagefor details.
If this does not correct the problem, reinstall Anaconda.