How To Install Python Package Numpy, Pandas, Scipy, Matplotlib On Windows, Mac And Linux

If you want to do data analysis in python, you always need to use python packages like Numpy, Pandas, Scipy and Matplotlib, etc. All those python packages are so powerful and useful to do Base N-dimensional array computing( Numpy ), Data structures & analysis ( Pandas ), scientific computing ( Scipy ), and Comprehensive 2D Plotting ( Matplotlib ). But the first step is to install the related packages on your OS, this article will tell you how to install them on Windows, Mac, and Linux.

1. Install Numpy, Pandas, Scipy, Matplotlib With Anaconda.

  1. Anaconda is a python edition that is used in scientific areas, so if you install Anaconda, all the above packages will be installed automatically. So please read the article How To Install Anaconda On Linux, Windows, macOS Correctly to install anaconda first.
  2. After installation, you can run command conda in a terminal to list the above packages to make sure it has been installed correctly like below.
    ~$ conda list pandas
    # packages in environment at /home/zhaosong/anaconda3:
    #
    # Name                    Version                   Build  Channel
    pandas                    0.23.4           py37h04863e7_0
  3. To list all installed anaconda packages, just run the command $ conda list.
  4. Run $ conda -h to list the conda command help information.
  5. If you want to remove/uninstall a package, run $ conda remove <package name>

2. Install Numpy, Pandas, Scipy, Matplotlib By PIP Command.

  1. First, make sure pip has been installed on your OS. If it is not installed, please refer article How To Install Python/Pip On Windows.
    ~$ pip --version
    pip 18.1 from /home/zhaosong/anaconda3/lib/python3.7/site-packages/pip (python 3.7)
    
  2. Run pip install command to install related packages.
    pip install numpy
    
    pip install pandas
    
    pip install scipy
    
    pip install matplotlib
    
    
  3. Run pip uninstall command to uninstall related packages.
    pip uninstall numpy
    
    pip uninstall pandas
    
    pip uninstall scipy
    
    pip uninstall matplotlib
  4. Run pip show command to display package install information.
    ~$ pip show pandas
    Name: pandas
    Version: 0.23.4
    Summary: Powerful data structures for data analysis, time series, and statistics
    Home-page: http://pandas.pydata.org
    Author: None
    Author-email: None
    License: BSD
    Location: /home/zhaosong/anaconda3/lib/python3.7/site-packages
    Requires: python-dateutil, pytz, numpy
    Required-by: seaborn, odo

3. How To Install Correct Numpy, Scipy, Matplotlib Package For Multiple Python Versions.

  1. I have 2 python versions installed on my Ubuntu Linux OS, they are python 2.7 and python 3.8. The python 2.7 is a built-in python version when I installed Ubuntu. And I install python 3.8 manually.
  2. Now I want to install the Scipy library on my Ubuntu Linux OS, and I find the below command in scipy.org, then I run the below command in a terminal.
    python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
  3. But when the above command execution was complete, I found it only install the NumPy, Scipy, Matplotlib, iPython, etc for python 2.7. It does not install the packages for python 3.8 as I want, how can I resolve this issue? Thanks a lot.
  4. This is because Ubuntu Linux installed python 2.7 by default, then the default pip command is also of python version 2.7.
  5. So when you run the python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose command, it will use python 2.7’s pip command to install.
  6. To fix this issue, you need to first install the pip command for python 3.8 ( sudo apt-get install python3-pip ), and then run the pip3 command to install all the Scipy packages for python 3.8 ( python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose ).

4. How To Fix The Error: Setup Script Exited With Pandas Requires Numpy >= 1.6 Due To Datetime64 Dependency During The Installation Of Python Pandas.

  1. I use macOS version 10.15 to develop a python program, and I want to install pandas in it.
  2. I run the command sudo easy_install pandas to install it, and it returns an error message like below.
    error: Setup script exited with pandas requires NumPy >= 1.18 due to datetime64 dependency
  3. So I get my Numpy version by executing the command pip show numpy like below, I find the installed Numpy version is less than 1.18.
    $ pip show numpy
    Name: numpy
    Version: 1.16.1
    Summary: NumPy is the fundamental package for array computing with Python.
    Home-page: https://www.numpy.org
    Author: Travis E. Oliphant et al.
    Author-email: None
    License: BSD
    Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
  4. So I run the command sudo easy_install numpy to install the python NumPy package and its success.
  5. When I run the command sudo easy_install pandas to install the python pandas package again, the error message still exists.
  6. I finally find the below method to fix this error.
  7. Open a dos window, then run the command python to go to the python interactive console.
    (MyPythonEnv) C:\Users\zhaosong>python
    Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
  8. Then run the below command to get the existing Numpy package installation directory.
    >>> import numpy
    >>> print(numpy)
    <module 'numpy' from 'C:\\Users\\zhaosong\\anaconda3\\envs\\MyPythonEnv\\lib\\site-packages\\numpy\\__init__.py'>
  9. Go to the python Numpy module installed directory and remove the entire directory.
  10. Now you can install the latest version of Numpy with the command sudo easy_install numpy or sudo pip install numpy.
3.3 3 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Clicky
0
Would love your thoughts, please comment.x
()
x