Installing SciPy

SciPy is the scientific Python library and is closely related to NumPy. In fact, SciPy and NumPy used to be one and the same project many years ago. In this recipe, we will install SciPy.

Getting ready

In Chapter 1, Winding Along with IPython, we discussed how to install setup tools and pip. Reread the recipe if necessary.

How to do it...

In this recipe, we will go through the steps for installing SciPy.

  • Installing from source: If you have Git installed, you can clone the SciPy repository using the following command:
    git clone https://github.com/scipy/scipy.git
    
    python setup.py build
    python setup.py install --user   
    

    This installs to your home directory and requires Python 2.6 or higher.

    Before building, you will also need to install the following packages on which SciPy depends:

    • BLAS and LAPACK libraries
    • C and Fortran compilers

    There is a chance that you have already installed this software as a part of the NumPy installation.

  • Installing SciPy on Linux: Most Linux distributions have SciPy packages. We will go through the necessary steps for some of the popular Linux distributions:
    • In order to install SciPy on Red Hat, Fedora, and CentOS, run the following instructions from the command line:
      yum install python-scipy
      
    • In order to install SciPy on Mandriva, run the following command line instruction:
      urpmi python-scipy
      
    • In order to install SciPy on Gentoo, run the following command line instruction:
      sudo emerge scipy
      
    • On Debian or Ubuntu, we need to type the following:
      sudo apt-get install python-scipy
      
  • Installing SciPy on Mac OS X: Apple Developer Tools (XCode) is required, because it contains the BLAS and LAPACK libraries. It can be found either in the App Store, or in the installation DVD that came with your Mac, or you can get the latest version from Apple Developer's connection at https://developer.apple.com/technologies/tools/. Make sure that everything, including all the optional packages is installed.

    You probably already have a Fortran compiler installed for NumPy. The binaries for gfortran can be found at http://r.research.att.com/tools/.

  • Installing SciPy using easy_install or pip: Install with either of the following two commands:
    sudo pip install scipy
    easy_install scipy
    
  • Installing on Windows: If you have Python installed already, the preferred method is to download and use the binary distribution. Alternatively, you may want to install the Enthought Python distribution, which comes with other scientific Python software packages.
  • Check your installation: Check the SciPy installation with the following code:
    import scipy
    print scipy.__version__
    print scipy.__file__

    This should print the correct SciPy version.

How it works...

Most package managers will take care of any dependencies for you. However, in some cases, you will need to install them manually. Unfortunately, this is beyond the scope of this book. If you run into problems, you can ask for help at:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset