At the time when this book was written, the latest versions of Python are 2.7.3 and 3.2.3. They are both stable production releases, although the Python 2 versions are more convenient if the user needs to communicate with third-party applications. No new releases are done for Python 2, and that is why Python 3 is considered "the present and the future of Python". For the purposes of SciPy applications, we do recommend to stay with the 2.7.3 version. The language can be downloaded from the official Python site (www.python.org/download) and installed on all major systems such as Windows, Mac OS X, Linux, and Unix. It has also been ported to other platforms, including Palm OS, iOS, PlayStation, PSP, Psion, and so on. The following screenshot shows two popular options for coding in Python on an iPad – PythonMath and Sage Math. While the first application allows only the use of simple math libraries, the second permits the user to load and use both NumPy and SciPy remotely.
PythonMath and Sage Math bring Python coding to iOS devices. Sage Math allows importing NumPy and SciPy.
We shall not go into detail about the installation of Python on your system, since we already assume familiarity with this language. In case of doubt, we advise browsing the excellent book Expert Python Programming: Best practices for designing, coding, and distributing your Python software, Tarek Ziadé, Packt Publishing, where detailed explanations are given for installing any of the different implementations on different systems. It is usually a good idea to follow the directions given on the official Python website, as well. We will also assume familiarity with carrying out interactive sessions in Python, as well as writing standalone scripts.
The latest libraries for both NumPy and SciPy can be downloaded from the official SciPy site, scipy.org/Download. They both require a Python Version 2.4 or newer, so we should be in good shape at this point. We may choose to do the download from sourceforge (sourceforge.net/projects/scipy), or from Git repositories (for instance, the superpack from fonnesbeck.github.com/ScipySuperpack). It is also possible in some systems to use pre-packaged executable bundles that simplify the process. We will show here how to download and install in the most common cases.
For instance, in Mac OS X, if macports
is installed, the process could not be easier. Open a terminal as superuser and, at the prompt (%
), issue the following command:
% port search scipy
This presents a
list of all ports that either install SciPy or use SciPy as a requirement. On that list, the one we require for Python 2.7 is the py27-scipy
port. We install it (again as a superuser) by issuing the following command at prompt:
% port install py27-scipy
A few minutes later, the libraries are properly installed and ready to use. Note how macports
also installs all needed requirements for us (including the NumPy libraries) without any extra effort from our part.
Under any other Unix/Linux system, if either no ports are available or if the user prefers to install from the packages downloaded from either sourceforge or Git, it is enough to perform the following steps:
Unzip the NumPy and SciPy packages following the recommendation of the official pages. This creates two folders, one for each library.
Within a terminal session, change directories to the folder where the NumPy libraries are stored, that contains the
setup.py
file. Find out which Fortran compiler you are using (one ofgnu
,gnu95
, orfcompiler
), and at prompt, issue the following command:% python setup.py build –fcompiler=<compiler>
Once built, and on the same folder, issue the installation command. This should be all.
% python setup.py install
Under Microsoft Windows, we recommend you install from the binary installers provided by the Enthought Python Distribution. Download and double-click!
The procedure for the installation of the SciPy libraries is exactly the same, that is, downloading and building before installing under Unix/Linux, or downloading and double-clicking under Microsoft Windows. Note that different implementations of Python might have different requirements before installing NumPy and SciPy.