What follows are instructions for setting up an Ubuntu 8.04 ("Hardy Heron") home environment for use with this book. I use Ubuntu GNU/Linux for both development and testing of the book, so it is the only system about which I can personally answer setup and configuration questions.
In the spirit of software freedom and open collaboration, please contact me if you would like to maintain a similar appendix for your own favorite system. I'd be more than happy to link to it or put it on the Open Book Project site, provided you agree to answer user feedback concerning it.
Thanks!
Jeffrey Elkner
Arlington Public Schools
Arlington, Virginia
A.1 Vim
Vim can be used very effectively for Python
development, but Ubuntu only comes with the vim-tiny package
installed by default, so it doesn't support color syntax highlighting or
auto-indenting.
To use Vim, do the following:
-
From the unix command prompt, run:
sudo apt-get install vim-gnome
-
Create a file in your home directory named
.vimrcthat contains the following:syntax enable filetype indent on set et set sw=4 set smarttab map <f2> :w\|!python %<cr>
When you edit a file with a .py extension, you should now
have color systax highlighting and auto indenting. Pressing the <F2>
key should run your program, and bring you back to the editor when the
program completes.
To learn to use vim, run the following command at a unix command prompt:
vimtutor
A.2 GASP
Several of the case studies use GASP (Graphics API for Students for Python), which is the only additional library needed to use this book.
To install GASP, do the following:
-
Add Mathew Gallagher's personal package archive to your apt sources:
- click
System -> Administration -> Software Sources - select the
Third-Party Softwaretab - click the
+ Addbutton - paste the following into the
APT line:text entry box:deb http://ppa.launchpad.net/mattva01/ubuntu hardy main restricted universe multiverse
- click the
Closebutton - click the
Reloadbutton inThe information about available software is out-of-datedialog box - click the
Closebutton of theSoftware Sourceswindow
- click
-
Install GASP by typing the following at a command prompt:
sudo apt-get install python-gasp
A.3 $HOME environment
The following creates a useful environment in your home directory for adding your own Python libraries and executable scripts:
- From the command prompt in your home directory, create
binandlib/pythonsubdirectories by running the following commands:mkdir bin lib mkdir lib/python
-
Add the following lines to the bottom of your
.bashrcin your home directory:PATH=$HOME/bin:$PATH PYTHONPATH=$HOME/lib/python EDITOR=vi export PATH PYTHONPATH EDITOR
This will set your prefered editor to Vim, add your ownlib/pythonsubdirectory for your Python libraries to your Python path, and add your ownbindirectory as a place to put executable scripts.
A.4 Making a python script executable and runnable from anywhere
On unix systems, Python scripts can be made executable using the following process:
- Add this line as the first line in the script:
#!/usr/bin/env python - At the unix command prompt, type the following to make
myscript.pyexecutable:chmod +x myscript.py
-
Move
myscript.pyinto yourbindirectory, and it will be runnable from anywhere.