Table of Contents
- Python Bootcamp
- Installing Python
- Basic Data Types
- Using Functions and Modules
- Modules, Scripts, Packages and Classes
- Using NumPy
- Graphing with MatPlotLib
- Using Scipy
- Statistics in Python with R
- Working With Python
- Using Python and FORTRAN with F2py
- Extending python with C/C++ using SWIG
- Using the C/Python Interface
- Speeding up Python with Cython
- Python/C Extension: PyTables
- Python/C Extension: PyTAPS
- Creating IRC and Email Bots
- Web Development: An introduction to Django
- GIS and Hardware Interface Example
- Advanced Python
- Making GUI's with WxPython
- Batteries Included - The Python Standard Library
Installing Python
Python Boot Camp 2010 - Session 1 - January 12
Presented By: Matt McCormick
Installation instructions
Windows Enthought (Recommended Windows Installation)
Windows Python(x,y) (Alternative Windows installation)
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 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 here.
Required software
The recommended installation instructions exceed the requirements listed here.
- 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.
- IPython >= 0.8.4::
An enhanced interactive Python shell. An architecture for interactive parallel computing.
- NumPy >= 1.1.0::
High performance numerical arrays.
- matplotlib >= 0.98::
2D plotting library
- R >= 2.7.1::
Language and environment for statistical computing and graphics
- RPy2 >= 2.0.4::
Python interface to the R Programming Language
- 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 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
2. Download the following file to your desktop: install-test.py. (Right click + Save Target As...)
3. 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
4. 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
5. 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 the Berkeley Python BootCamp
A good place to start learning about the Python language is the Python tutorial. A good place to get started with NumPy, the scientific computing foundation in Python, is the introductory 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:
- The SciPy wiki has on excellent cookbook with recipes for what you want to do (yum!).
- The NumPy reference guide: contains a lot of useful information on array manipulation and basic mathematical operations.
- The SciPy reference guide: is easily browsable and describes the more complex mathematics available.
- The Matplotlib manual: this is the matlab-like plotting library we’ll be using throughout.
- The IPython manual: the interactive environment you’ll be working in.
- The SciPy documentation page contains links to many more documentation resources, especially for scientific work.
- PyPi, the Python Package Index, is an easily searchable, comprehensive database of Python packages.
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.
![(please configure the [header_logo] section in trac.ini)](/cgi-bin/hackerwithin.fcgi/chrome/site/thwlogo-small.png)