If you are a student in a course where the software infrastructure is already installed, you just need to make sure your set-up of environment variables is ok (the INF3330/4330/5660 courses at the University of Oslo employ this set-up).
apt-get install gnuplot python idle python-pmw python-numeric python-numarray python-scipy python-scipy-core python-scientific python-psyco python-imaging-tk python-happydoc python-epydoc python-docutils python-gnuplot python-f2py pylint ipython ipython-common swig libreadline5-dev gcc-3.4 g++-3.4 g77-3.4You will also need mpeg_encode, but that package does not compile well with gcc-3.4 and newer versions. A fix is found in src/mpeg_encode included in the SYSDIR-misc.tar.gz file (pack out and run install/mpeg_encode, see below).
export MACHINE_TYPE=`uname -s` export SYSDIR=$HOME/ext export PREFIX=$SYSDIR/$MACHINE_TYPE export PATH=$PREFIX/bin:$PATH export scripting=$HOME/scripting export PYTHONPATH=$SYSDIR/src/python/tools:$scripting/src/tools export PATH=$scripting/src/tools:$scripting/$MACHINE_TYPE/bin:$PATH export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH export MANPATH=$PREFIX/man:$MANPATHThis is just a suggestion. The important thing is that you define the environment variables scripting, SYSDIR, MACHINE_TYPE, PATH, PYTHONPATH, and LD_LIBRARY_PATH (those who do not want to use LD_LIBRARY_PATH must link the libraries by an appropriate alternative procedure).
The syntax of the start-up file .tschrc for csh or tcsh users has slightly different syntax than exemplified for the .bashrc file (setenv instead of export etc.). If you are uncertain about the right syntax, I encourage you to move to the superior Bash shell at once and make a .bashrc file instead ;-)
tar xzf *.tar.gzThere are several scripts install/* for installing the packages in $SYSDIR/src. For example, to install Python and all the associated modules and tools, first run install/python and then install/python_modules.py when standing in $SYSDIR/src.
Start with running the scripts
install/zlib install/tcl tcl tk blt tix install/readlineThe tix part is optional (not used in the book).
The jpeg library is required by Python's PIL package for image processing:
install/jpegInstalling the basic Python interpreter is accomplished by
install/pythonAdditional modules can be installed by
install/python_modules.py(make sure scripting-src.tar.gz is already packed out).
Note that there is currently a problem with Numeric and gcc (some functions from the LinearAlgebra module hang): the fix is to add the compiler flag -ffloat-store, e.g., CFLAGS='-ffloat-store' python setup.py. This is done by python_modules.py, but might cause problems if other compilers than gcc are used. Go to the Numeric directory in that case and run python setup.py install manually after you have run python_modules.py.
If you want successful installs of PySparse and SciPy, you should install LAPACK and ATLAS prior to running install/python_modules.py:
install/lapack install/atlas install/python_modules.pyLAPACK, ATLAS, PySparse, and SciPy may cause you problems so be prepared to read the install scripts and launch the commands manually. Even if LAPACK and/or ATLAS fail, install/python_modules.py should give you all necessary packages except for SciPy and PySparse. The install/python_modules.py script can be run with a collection of command-line arguments(like Numeric, SciPy, PIL, etc.) to install individual packages. Problems with SciPy may occur with gcc/g77 version 4.0, but v3.x should work well.
Some introductory Python examples in the book make use of epsmerge and mpeg_encode, which are installed by
install/epsmerge install/mpeg_encodeIf you want Jython and have JDK installed, you can say
install/jython(Jython is not used explicitly in the book).
Now you can install various useful utilities used in the book (libpng and ImageMagick also needs zlib):
install/libpng install/ImageMagick install/gd install/gnuplot
If you encounter problems, try to run the commands in the install/*
scripts manually
and read the README or INSTALL files that
come with the packages.
The install/* scripts have been run (at least) on
Linux (Debian and RedHat) and Sun Solaris systems.
First you should define some environment variables. The standard way of doing this in Windows XP (or 2000) is to use a graphical utility: Right-click My Computer, then click Properties, choose the Advanced tab, and click Environment Variables. Click New to add a new environment variable with a name and a value, e.g., scripting as name and
C:\Documents and Settings\hpl\My Documents\scriptingAlternatively, you can add a line in the Windows start-up file C:\autoexec.bat if you have administrator privileges. This technique is discouraged on Windows XP, but it works and is handy if you want to copy set-ups between different machines. On Windows 95/98/ME you must use autoexec.bat. The magic line in this file has the syntax
set name=valueRight below is an example of the four environment variables you need to set.
name value scripting C:\Documents and Settings\hpl\My Documents\scripting PYTHONSRC C:\Python23 PATH %PATH%;%scripting%\src\tools;%PYTHONSRC%;C:\Gnuplot4.0\gnuplot\bin PYTHONPATH %scripting%\lib;%scripting%\src\toolsNote that this is only an example - your software packages may have other version numbers and they may be placed in different directories.
If you use Python under both Windows and Cygwin, ensure that the Cygwin start-up file does not add directories to what Windows has already set PYTHONPATH to (i.e., avoid export PYTHONPATH=$PYTHONPATH:/new/paths). Otherwise PYTHONPATH will contain both colon and semi-colon as directory delimiters, corrupts the value of this variable. Note that the scripting variable contains blanks so it might be necessary, especially in Windows batch files (.bat scripts), to enclose scripting paths in quotes, like "%scripting%\src\tools".
Instead of setting PYTHONPATH you can install the modules and packages in %scripting%\src\tools by running setup.py in %scripting%\src (after Python itself is installed).
The next step is to install Python. I recommend either the ActivePython or the Enthought version. ActivePython requires installation of Numerical Python modules included in the zipfile, while the Enthought version includes Numerical Python, SciPy, Vtk, MayaVi, and many other useful modules.
If you prefer the Enthought edition (I do!), go to the Web page
http://www.enthought.com/and download the latest binary Python version for Windows. (At the time of this writing, September 2005, the 2.3.5 version was unstable so you should stick to the previous v2.3.3.) Double click on the .exe file to install everything in the Enthought package. The start-program menu item automatically contains an entry for the IDLE shell as well as documentation and demos.
If you prefer ActivePython, go to the ActiveState Web page,
http://www.activestate.com/Products/ActivePython/and download the latest Windows version of ActivePython. You might also need to install InstMsiA.exe prior to installing Python, unless this program is already available on your computer. When ActivePython is up and running, you should install the Numerical Python modules from the zipfile, either Numeric or numarray (or both). In addition you must install PIL. Just double click on the .exe files and follow the guidelines. The default answers are appropriate unless you have special needs. I recommend to set up the IDLE environment as this gives you a user-friendly interactive Python shell and a convenient editor for writing Python programs. Go to the directory PythonX\Lib\idlelib (usually the PythonX directory tree is installed under C:\), where X denotes the current version of Python. Make a short cut to the file idle.py and move the icon to the desktop. Double clicking on the icon launches the IDLE interactive shell, and from the menu bar you can launch the editor and the debugger.
When ActivePython or Enthought's Python package is installed, you can continue with other files in WinScripting.zip. Open the Pmw.X.tar.gz file (X denotes the version number of the current Pmw distribution) with WinZip. If you do not have the WinZip program, you can download it from www.winzip.com. Pack out the file and store the resulting file tree in a directory contained in the Python seach paths. To see the search paths, invoke the IDLE shell and write
import sys; sys.pathOne possible place to move the Pmw tree of files is the official Python module directory
C:\PythonX\Lib\site-packagesYou can also pack the tree of files out in an arbitrary directory and just add the path of that directory to the PYTHONPATH environment variable in the autoexec.bat file.
Continue with installing the ImageMagick package by just double clicking on the associated .exe file. The Ghostscript (gs) package is also installed by a simple double click on an .exe file whose name starts with gs. To make a command like ps2pdf work (needed in Chapter 2), the lib directory where gs is installed must be added to the PATH variable. The appropriate value of \emp{PATH} is then %PATH%;C:\gs\gs814\lib (the particular name of the path depends of course on the version number of Ghostscript).
The interactive IPython shell is useful on Windows. Double click on the relevant .exe file to invoke the IPython installer.
Gnuplot is installed by opening the Gnuplot zipfile with WinZip, clicking on "extract", and choosing C:\Gnuplot4.0.0 as directory for extraction. All executable files in the Gnuplot distribution for Windows are now in the gnuplot\bin subdirectory. Make sure that this directory is registered in the PATH variable.
To make Gnuplot behave similarly on Unix and Windows, I have made a scripting interface to Gnuplot on Windows. The file gnuplot.bat is the front end and runs
python "%scripting%\src\tools\_gnuplot.py" %1 %2 %3 %4 %5 %6 %7 %8The gnuplot.bat file is available in %scripting%\src\tools such that writing just gnuplot in any directory lanuches gnuplot.bat, which launches _gnuplot.py, which finally launches the Gnuplot plotting program. The _gnuplot.py file is a script that allows the same command-line arguments to Gnuplot on Windows as on Unix.
Tcl/Tk for Tkinter GUIs is automatically installed along with ActivePython or the Enthought Python version, but BLT needs to be installed separately. This might be a bit tricky:
The example codes associated with this book appear in scripting-src.tar.gz. Open the file with WinZip, click on "extract" and choose
C:\Documents and Settings\hpl\My Documents\scriptingas extraction directory (this must be consistent with the contents of %scripting%). The result is a directory tree src and a file doc.html (which should be immediately bookmarked in your Web browser).
Also pack out scripting-doc.tar.gz file in the %scripting% directory using the same recipe.
Many of the scripts used in this book make use of the oscillator code. The simplest approach on Windows is to use the Python version of the oscillator code. The file is
%scripting%\src\app\oscillator\Python\oscillator.pyOtherwise you need to compile the Fortran or C version. There is a Windows script, oscillator.bat in %scripting%\src\tools, which makes it possible to run the oscillator code by just writing oscillator (in any directory). This allows Windows scripts to use oscillator exactly as we do on Unix.
To integrate Python with Fortran, C, and C++ as explained in Chapter 4, you need compilers for these languages. The simplest approach is to install Cygwin, a free Unix environment that runs in Windows operating systems. Cygwin comes with GNU compilers, Python, and Unix shells such that you apply all the recipes from Chapter 4 more or less directly. Enthought's excellent Python edition is compiled with Visual C++, so if you want to compile extension modules in C or C++ you need Visual C++. In case you do not have Visual C++ or do not want to buy it, Cygwin and the GNU compiler suite is an alternative solution. Then you need to use the Cygwin version of Python and install the modules you need manually (this is basically the same procedure as you would follow on Unix/Linux systems). Note that GNU compiled extension modules made under Cygwin will not work if combined with Enthought's Python edition.
Files with a certain extension can on Windows be associated with a file type, and a file type can be associated with a particular application. This means that when we write the name of the file, the file is handled by an application: instead of writing python somescript.py we can just write somescript.py. It is useful to associate .py extensions with a Python interpreter. Start a DOS command line prompt and issue the commands
assoc .py=PyScript ftype PyScript=python.exe "%1" %*Depending on your Python installation, such file extension bindings may already be done. You can check this with
assoc | find "py"To see the application associated with a file type, write ftype name where name is the name of the file type as specified by the assoc command. Writing help ftype and help assoc prints out more information about these commands along with examples.
One can also run Python scripts by writing just the basename of the script file, i.e., somescript instead of somescript.py, if the file extension is registered in the PATHEXT environment variable:
PATHEXT=%PATHEXT%;.py
./test_allutils.py # or python test_allutils.pyThis script checks if all Python and Perl utilities you may need are available. The next section describes how to obtain the source code of all the software you need and how to install it.