Let's get started. We will install NumPy and related software on different operating sytems and have a look at some simple code that uses NumPy. As mentioned in the Preface, SciPy is closely related to NumPy, so you will see the name SciPy appearing throughout the chapter. At the end of this chapter, you will find pointers on how to find additional information online if you get stuck or are uncertain about the best way to solve problems.
In this chapter, we shall learn the following skills:
Installing Python, SciPy, Matplotlib, IPython, and NumPy on Windows, Linux, and Macintosh
Writing simple NumPy code
Adding arrays
Making use of online resources and help
NumPy is based on Python, so it is required to have Python installed. On some operating systems, Python is already installed. You, however, need to check whether the Python version is compatible with the NumPy version you want to install. There are many implementations of Python, including commercial implementations and distributions. In this book, we will focus on the standard CPython implementation, which is guaranteed to be compatible with NumPy.
NumPy has binary installers for Windows, various Linux distributions, and Mac OS X. There is also a source distribution, if you prefer that. You need to have Python 2.4.x or above installed on your system. Python 2.7.6 is currently the best Python version to have because most scientific Python libraries support it.
Installing NumPy on Windows is a necessary but, fortunately, straightforward task that we will cover in detail. You only need to download an installer, and a wizard will guide you through the installation steps. It is recommended that Matplotlib, SciPy, and IPython be installed. However, this is not required to enjoy this book. The actions we will take are as follows:
Download a NumPy installer for Windows from the SourceForge website at http://sourceforge.net/projects/numpy/files/.
Choose the appropriate version. In this example, we chose
numpy-1.8.0-win32-superpack-python2.7.exe
.Open the EXE installer by double-clicking on it.
Now, we can see a description of NumPy and its features, as shown in the previous screenshot. Click on the Next button.
If you have Python installed, it should automatically be detected. If it is not detected, maybe your path settings are wrong. At the end of this chapter, resources are listed in case you have problems installing NumPy.
In this example, Python 2.7 was found. Click on the Next button if Python is found, otherwise, click on the Cancel button and install Python (NumPy cannot be installed without Python). Click on the Next button. This is the point of no return. Well, kind of, but it is best to make sure that you are installing to the proper directory and so on and so forth. Now the real installation starts. This may take a while.
Install SciPy and Matplotlib with the Enthought distribution at http://www.enthought.com/products/epd.php.
Note
The situation around installers is rapidly evolving. Other alternatives exist in various stage of maturity (see http://www.scipy.org/install.html). It might be necessary to put the
msvcp71.dll
file in yourC:\Windows\system32
directory. You can get it at http://www.dll-files.com/dllindex/dll-files.shtml?msvcp71. A Windows IPython installer is available on the IPython website (see http://ipython.scipy.org/Wiki/IpythonOnWindows).