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.
- 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.
- 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
- To list all installed anaconda packages, just run the command
$ conda list.
$ conda -hto list the conda command help information.
- If you want to remove/uninstall a package, run
$ conda remove <package name>
2. Install Numpy, Pandas, Scipy, Matplotlib By PIP Command.
- 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)
- Run pip install command to install related packages.
pip install numpy pip install pandas pip install scipy pip install matplotlib
- Run pip uninstall command to uninstall related packages.
pip uninstall numpy pip uninstall pandas pip uninstall scipy pip uninstall matplotlib
- 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.
- 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.
- 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
- 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.
- This is because Ubuntu Linux installed python 2.7 by default, then the default pip command is also of python version 2.7.
- So when you run the
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nosecommand, it will use python 2.7’s pip command to install.
- 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.
- I use macOS version 10.15 to develop a python program, and I want to install pandas in it.
- 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
- 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
- So I run the command sudo easy_install numpy to install the python NumPy package and its success.
- When I run the command sudo easy_install pandas to install the python pandas package again, the error message still exists.
- I finally find the below method to fix this error.
- 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. >>>
- 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'>
- Go to the python Numpy module installed directory and remove the entire directory.
- Now you can install the latest version of Numpy with the command sudo easy_install numpy or sudo pip install numpy.