Skip to content

PyBCSession01

Katy Huff edited this page Jan 29, 2012 · 7 revisions

Other Wiki Pages: PyBc, Session01, Session02, Session03, Session04, Session05, Session06, Session07, Session08, Session09, f2py, swig, Cpython, Cython, PyTables, PyTaps, PythonBots, Django, GIS, AdvancedPython, WxPython, standardlib,

Installing Python

Python Boot Camp 2010 - Session 1 - January 12


Presented By: Matt !McCormick

Installation instructions

InstallPythonOnLinux Linux]]

InstallPythonOnOSX Mac OS X]]

To follow along the boot camp sessions, you need to have python and some additional software installed. We've included installation instructions below which will help you install the required software on Windows, Mac OSX, and Linux. If you are tech/python savvy and want to install everything on your own, then a list of required software is shown below. If you do not have or are unwilling to install the necessary software on your laptop, then you may check Windows/Mac laptops out from the library for free if you are a UW student or employee. Go [http://ecs.library.wisc.edu here] for more information. Note, that whenever you install any software, there is a chance you will break something - so if you are uncomfortable with following these instructions, then please check a library out from the library. However, the software we are asking you to install is fairly benign and is necessary if you are interested in developing scientific applications in python.

Due to the large response to the boot camp, we are asking participants who feel comfortable to attempt the software installation themselves. The installation requires downloading several hundred megabytes of data which could overwhelm the wireless network if everyone attempts it at the boot camp.

Mac OSX users: You will need to install the Apple Developer Tools (also known as Xcode) in order to install the software necessary for the statistics in python session. Xcode can be found on the OSX DVDs or can be downloaded. However, due to the large download size (~1GB) we would like participants to install Xcode themselves. You can find download instructions [http://hackerwithin.org/cgi-bin/hackerwithin.fcgi/wiki/[[Xcode here].|PyBCXcode here].]]

Required software

The recommended installation instructions exceed the requirements listed here.

  • [http://python.org Python] >= 2.5 :
    Provides the python library, interpreter, and the extensive standard library. Since most dependencies have not migrated, Python 3.X will not be used at this bootcamp.
  • [http://ipython.scipy.org/ IPython] >= 0.8.4 :
    An enhanced interactive Python shell. An architecture for interactive parallel computing.
  • [http://numpy.scipy.org/ NumPy] >= 1.1.0 :
    High performance numerical arrays.
  • [http://matplotlib.sourceforge.net/ matplotlib] >= 0.98 :
    2D plotting library
  • [http://www.r-project.org/ R] >= 2.7.1 :
    Language and environment for statistical computing and graphics
  • [http://rpy.sourceforge.net RPy2] >= 2.0.4 :
    Python interface to the R Programming Language
  • [http://scipy.org/ scipy] >= 0.6.0 :
    User-friendly and efficient numerical routines such as routines for numerical integration and optimization.

Text editor

A programmer's text editor is needed. If you do not have a preferred editor, standard python comes with [http://docs.python.org/library/idle.html IDLE], a Tk based IDE. IDLE is distributed with python and capable for our purposes.

Testing your installation

Test installed packages

Once you have installed everything you need, you can test your installation by following the instructions below.

  1. Open ipython and run your first command by opening a python interpreter (by running ipython).
::
In [1]: print "hello world" hello world
  1. Download the following file ''to your desktop'': [http://github.com/thewtex/thwpybc2010it/raw/master/install-test.py install-test.py]. (Right click + ''Save Target As...'')
  2. The ipython shell has many useful tools for interactive computing not found in the vanilla python shell. This includes pwd, cd, and ls, which behave similar to their Unix equivalents, along with ''Tab'' completion and ''GNU readline'' support. cd to the directory containing ''install-test.py''.
In [2]: cd
/home/matt

In [3]: cd Desktop/ /home/matt/Desktop

In [4]: ls install-test.py install-test.py
  1. While python scripts can be run as independent executables, the ipython shell contain a function to run scripts interactively but in an independent namespace: %run. Execute the install test script with
In [5]: %run install-test.py
Checking Python version...
Success.

Checking for modules...
Success:  IPython
Success:  matplotlib
Success:  numpy
Success:  rpy2
Success:  scipy

Checking for Python IDLE IDE...
Success.


Required Dependencies:
Adequate version found: ['IPython', 'matplotlib', 'numpy', 'rpy2', 'scipy']
Adequate version not found:  []

Text Editor:

IDLE IDE was found.

A programmer's text editor is needed.  If you do not have a preferred editor,
the IDLE Python IDE comes with all python distributions and has a sufficient
text editor.

The output will tell you if all required dependencies are installed correctly. Ask for help from an instructor if you see the word FAILURE anywhere.

Bonus

  1. Try some cool python foo. Make your computer into an http file server with one line of code. In a system shell (''cmd.exe'' on Windows or ''/bin/sh'' on Unix), execute
python -c "import SimpleHTTPServer; SimpleHTTPServer.test()"

Next point your browser to [http://localhost:8000]

To terminate the server, and regain control of your terminal window, press CTL-C

Where to look for help

,,Adapted from [http://fperez.org/py4science/workshop_berkeley_2008.html the Berkeley Python BootCamp],,

A good place to start learning about the Python language is the [http://docs.python.org/tutorial Python tutorial]. A good place to get started with !NumPy, the scientific computing foundation in Python, is the introductory [http://mentat.za.net/numpy/intro/intro.html NumPy tutorial].

Note: in all of these, the markers that you see as >>> are the prompts generated by Python which you do not type. Similarly, the IPython prompts look like In [3]:.

In addition to these two tutorials, the following links can also be useful as reference:

However, scientific Python is best discovered interactively, which is facilitated by the IPython shell. The IPython header describes usage:

IPython 0.8.4 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.