Introduction to Linux - A Hands on Guide | Linux Bible | Linux From Scratch | A Newbie's Getting Started Guide to Linux | Linux Command Line Cheat Sheet | More Linux eBooks



Tuesday, 15 November 2016

Install NumPy, Pandas, Matplotlib and SciPy in Linux

NumPy, SciPy, Pandas and Matplotlib are the crucial packages required in scientific computing with Python. NumPy (or Numeric Python) is a library of mathematical functions that helps us solving problems related to matrices, N-dimensional arrays, Fourier series and linear algebra. SciPy is a library that provides tools useful in science, engineering and scientific computing. It also contains modules to solve problems on integration, interpolation, linear algebra, fast Fourier transform, digital signal and image processing. Matplotlib is the visualization package and plotting library that is used to create high quality plots, graphs, charts and histograms. In this article, we will be installing these tools on our CentOS system.

numpy-pandas-matplotlib-scipy-installation

First of all, we need Python installed on our system, which I have covered in our article on Python installation. Then we need to have pip, a package management tool with which we can install, uninstall and manage other packages written in Python, installed in our system.

1. pip Installation

There are multiple ways to install pip in linux. I preferred to use get-pip.py script to install pip. First, we need to download the script from the source and run it using python as we would run a normal script. The command to download the get-pip.py script is -

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"

Now, lets proceed with the installation.

# Downloading 'get-pip.py' using 'curl' command
[root@LinuxBox ~]$ curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1558k  100 1558k    0     0   483k      0  0:00:03  0:00:03 --:--:--  483k

# Installing 'pip' using 'get-pip.py'
[root@LinuxBox ~]$ python get-pip.py
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 134kB/s
Collecting setuptools
  Downloading setuptools-28.8.0-py2.py3-none-any.whl (472kB)
    100% |████████████████████████████████| 481kB 454kB/s
Collecting wheel
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 954kB/s
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-28.8.0 wheel-0.29.0

Now, with pip, we can install other packages written in Python as - pip install <package_name>

2. Installing NumPy

We need to run pip install numpy as below:

[root@LinuxBox ~]$ pip install numpy
Collecting numpy
  Downloading numpy-1.11.2-cp27-cp27mu-manylinux1_x86_64.whl (15.3MB)
    100% |████████████████████████████████| 15.3MB 8.6kB/s
Installing collected packages: numpy
Successfully installed numpy-1.11.2

To verify successful installation of the package, we enter the Python terminal, import the module and check it's version as below:

>>> import numpy
>>> print numpy.__version__
1.11.2

We will follow the same procedure to install other packages - pandas, matplotlib and scipy. Alternately, you can mention all four packages in one command to save your time and efforts as - pip install numpy pandas matplotlib scipy

3. Installing Pandas

[root@LinuxBox ~]$ pip install pandas
Collecting pandas
  Downloading pandas-0.19.1-cp27-cp27mu-manylinux1_x86_64.whl (16.7MB)
    100% |████████████████████████████████| 16.7MB 17kB/s
Requirement already satisfied: numpy>=1.7.0 in /usr/lib64/python2.7/site-packages (from pandas)
Collecting python-dateutil (from pandas)
  Downloading python_dateutil-2.6.0-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 671kB/s
Collecting pytz>=2011k (from pandas)
  Downloading pytz-2016.7-py2.py3-none-any.whl (480kB)
    100% |████████████████████████████████| 481kB 646kB/s
Collecting six>=1.5 (from python-dateutil->pandas)
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, pytz, pandas
Successfully installed pandas-0.19.1 python-dateutil-2.6.0 pytz-2016.7 six-1.10.0

>>> import pandas
>>> print pandas.__version__
0.19.1

4. Installing Matplotlib

[root@LinuxBox ~]$ pip install matplotlib
Collecting matplotlib
  Downloading matplotlib-1.5.3-cp27-cp27mu-manylinux1_x86_64.whl (13.7MB)
    100% |████████████████████████████████| 13.7MB 30kB/s
Requirement already satisfied: numpy>=1.6 in /usr/lib64/python2.7/site-packages (from matplotlib)
Requirement already satisfied: python-dateutil in /usr/lib/python2.7/site-packages (from matplotlib)
Collecting cycler (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Requirement already satisfied: pytz in /usr/lib/python2.7/site-packages (from matplotlib)
Collecting pyparsing!=2.0.0,!=2.0.4,!=2.1.2,>=1.5.6 (from matplotlib)
  Downloading pyparsing-2.1.10-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 1.6MB/s
Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/site-packages (from python-dateutil->matplotlib)
Installing collected packages: cycler, pyparsing, matplotlib
Successfully installed cycler-0.10.0 matplotlib-1.5.3 pyparsing-2.1.10

>>> import matplotlib
>>> print matplotlib.__version__
1.5.3

5. Installing SciPy

[root@LinuxBox ~]$ pip install scipy
Collecting scipy
  Downloading scipy-0.18.1-cp27-cp27mu-manylinux1_x86_64.whl (40.3MB)
    100% |████████████████████████████████| 40.3MB 6.3kB/s
Installing collected packages: scipy
Successfully installed scipy-0.18.1

>>> import scipy
>>> print scipy.__version__
0.18.1

That's all. Thank you.

0 comments:

Post a Comment