Book Image

SciPy Recipes

By : V Kishore Ayyadevara, Ruben Oliva Ramos
Book Image

SciPy Recipes

By: V Kishore Ayyadevara, Ruben Oliva Ramos

Overview of this book

With the SciPy Stack, you get the power to effectively process, manipulate, and visualize your data using the popular Python language. Utilizing SciPy correctly can sometimes be a very tricky proposition. This book provides the right techniques so you can use SciPy to perform different data science tasks with ease. This book includes hands-on recipes for using the different components of the SciPy Stack such as NumPy, SciPy, matplotlib, and pandas, among others. You will use these libraries to solve real-world problems in linear algebra, numerical analysis, data visualization, and much more. The recipes included in the book will ensure you get a practical understanding not only of how a particular feature in SciPy Stack works, but also of its application to real-world problems. The independent nature of the recipes also ensure that you can pick up any one and learn about a particular feature of SciPy without reading through the other recipes, thus making the book a very handy and useful guide.
Table of Contents (11 chapters)

Installing SciPy from a binary distribution on Windows

Windows does not ship with any version of Python pre-installed, which actually makes things easier when we want to install our own version of Python.

On the other hand, the installation of a full SciPy stack in Windows is somewhat more complex, due to conflicts that exist between the Python distribution and certain Windows libraries. We indicate an installation route that has been tested several times, but some trial and error may be necessary due to changes in the distribution.

How to do it...

To make the instructions easier to follow, the installation procedure is broken down into two stages:

  • Installing Python
  • Install the SciPy stack

Installing Python

  1. Go to https://www.python.org and download the Python 3 binary distribution for Windows
  2. Once the download finishes, double-click on the installation file to start the setup
  3. Check the box Add Python 3.x to PATH
  4. Click the Install Now option
  5. Select the Disable the path length limit option, if available, on the last installation screen
  6. Close the installation screen

These steps will install Python in the folder:

C:\Users\username\Appdata\Local\Programs\Python\Python3x

To test the installation, start a Command Prompt window and enter the following command:

python3

If all is correct, the Python command-line interpreter will start and display information about the version of Python being run. For now, just exit the interpreter by entering, at the >>> Python prompt, the following statement:

quit()

Now, let's check if pip was correctly installed. Enter the following at the command line:

pip --version

This should print information about the currently installed version of pip3, including the location where packages will be installed. As long as no errors are reported, the installation is correct.

Installing the SciPy stack

To install SciPy, we need to first download the versions of the library that have been built specifically for Windows. They can be found at the following site: http://www.lfd.uci.edu/~gohlke/pythonlibs/.

This page contains a long list of pre-compiled Python packages for Windows. Search the page for numpy-mkl and scipy and look for a package that matches your operating system and Python distribution. In my case, I found the following two files:

numpy-1.12/1+mkl-cp36-cp36m-win_amd64.whl
scipy-0.19.0-cp36-cpm36m-win_amd64.whl

Notice that the package names refer to version 3.6 and a 64-bit architecture. Make sure the versions you download match your Python 3 distributions. Open a command window on the directory where the files were saved and enter the following two commands, in the following order:

pip install numpy-1.12/1+mkl-cp36-cp36m-win_amd64.whl
pip install scipy-0.19.0-cp36-cpm36m-win_amd64.whl

After installing NumPy and SciPy, pip can be used to install the other packages directly by running the commands shown as follows:

pip install matplotlib
pip install ipython jupyter
pip install pandas sympy nose

Let's now test the installation. First, start Python 3 and execute the following statements at the >>> Python prompt:

import numpy
import scipy
import matplotlib
import pandas
import IPython
import sympy

If you can run all these commands and there are no errors, the installation of the packages is correct. Exit the Python shell by running the following statement:

quit()

Now, back in the command window, run the following command:

ipython

This will start IPython and display information about the installed version. For now, simply exit IPython by running the following at the prompt:

quit()

Finally, let's test the Jupyter Notebook. At the command line, run the following command:

jupyter notebook

If all is correct, this will start the Jupyter Notebook in your browser after a few seconds. This finishes the installation of Python and the SciPy stack in Windows.