2. Installing NumPy

This chapter explains how to install and test NumPy, from either the source distribution or from the binary distribution.

Before we start with the actual tutorial, we will describe the steps needed for you to be able to follow along the examples step by step. These steps including installing Python, the NumPy extensions, and some tools and sample files used in the examples of this tutorial.

Testing the Python installation

The first step is to install Python if you haven't already. Python is available from the Python project page at http://sourceforge.net/projects/python. Click on the link corresponding to your platform, and follow the instructions described there. When installed, starting Python by typing python at the shell or double-clicking on the Python interpreter should give a prompt such as:

Python 2.1b2 (#12, Mar 23 2001, 14:01:30) [MSC 32 bit (Intel)] on win32

Type "copyright", "credits" or "license" for more information.

>>>

If you have problems getting this part to work, consider contacting a local support person or emailing python-help@python.org for help. If neither solution works, consider posting on the comp.lang.python newsgroup (details on the newsgroup/mailing list are available at http://www.python.org/psa/MailingLists.html#clp ).

Testing the Numeric Python Extension Installation

The standard Python distribution does not come as of this writing with the Numeric Python extensions installed, but your system administrator may have installed them already. To find out if your Python interpreter has NumPy installed, type import Numeric at the Python prompt. You'll see one of two behaviors (throughout this document, bold Courier New font indicates user input, and standard Courier New font indicates output):

>>> import Numeric

Traceback (innermost last):

File "<stdin>", line 1, in ?

ImportError: No module named Numeric

>>>

indicating that you don't have NumPy installed, or:

>>> import Numeric

>>>

indicating that you do. If you do, go on to the next step. If you don't, you have to get the NumPy extensions.

Installing NumPy

The release facility at SourceForge is accessed through the project page, http://sourceforge.net/projects/numpy. Click on the "numpy" releases and you will be presented with a list of the available files. The files whose names end in ".tar.gz" are source code releases. A .zip file is the source code in Windows format. The other files are binaries for a given platform.

It is possible to get the latest sources directly from our CVS repository using the facilities described at SourceForge. Note that while every effort is made to ensure that the repository is always "good", direct use of the repository is subject to more errors than using a standard release.

Installing on Windows

On Windows, we currently have available for each release an .exe file that should be executed. Doing so will install Numeric Python into your Python distribution. There are also .exe files for each of the optional packages. Note that some of the optional packages require other optional packages.

If you wish to build from source on Windows, the Unix procedure described below can be used, running python in a command-line tool, on the Windows-format sources in the .zip file.

In general, there may not be a prebuilt version of a particular kind available in every minor release. If you need a prebuilt version, choose the most recent version available.

Releases prior to 20 had binary .zip files for Windows; these have been replaced by the .exe files that contain genuine installers.

Installing on Unix

The source distribution should be uncompressed and unpacked using the the tar program:

csh> tar xfz Numeric-n.m.tar.gz

Follow the instructions in the top-level directory for compilation and installation. Note that there are options you must consider before beginning. Installation is usually as simple as:

python setup_all.py install

However, please (please!) see the README itself for the latest details.

 

Just like all Python modules and packages, the Numeric module can be invoked using either the import Numeric form, or the from Numeric import ... form. Because most of the functions we'll talk about are in the Numeric module, in this document, all of the code samples will assume that they have been preceded by a statement:

from Numeric import *

 
At the SourceForge...

The SourceForge project page for Numerical Python is at http://sourceforge.net/projects/numpy. On this project page you will find links to:

Go to Main Go to Previous Go to Next