how Install pandas with Python3.6.4 on ubuntu 16.04

When you have multiple python versions installed on your ubuntu, installing modles becomes kind of complex. Also, you need to install python modules separately for each version. Meaning, pandas installed with python 2.7 will not be available if you want to run script in python 3.6.

Lets check this. I had installed pandas with python2.7, I wanted to test if pandas installed for python2.7.x will work for python3.6.x as well ?


$ python3.6
Python 3.6.4 (default, Jan 13 2018, 12:02:51)  
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.  
>>> import pandas as pd
Traceback (most recent call last):  
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'  
>>> 

As you can see, pandas installed with python2.7.x does not work for python3.6.4.

I thought lets try to reinstall pandas but it said, pandas is already installed


$ pip install pandas
Requirement already satisfied: pandas in /usr/local/lib/python2.7/dist-packages  
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python2.7/dist-packages (from pandas)  
Requirement already satisfied: python-dateutil in /usr/local/lib/python2.7/dist-packages (from pandas)  
Requirement already satisfied: numpy>=1.7.0 in /usr/local/lib/python2.7/dist-packages (from pandas)  
Requirement already satisfied: six>=1.5 in /usr/local/lib/python2.7/dist-packages (from python-dateutil->pandas)  

my pip version is


$ pip -V
pip 9.0.1 from /home/conquistador/.local/lib/python2.7/site-packages (python 2.7)  

Ok so pip installed on my machine is of python2.7.x

Packages for Python 2 and Python 3 are installed separately, and installing in one version won’t make a package available to the other.

Finally i found a way to install pandas with python3.6.4


$ sudo python3.6 -m pip install pandas
The directory '/home/conquistador/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.  
The directory '/home/conquistador/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.  
Collecting pandas  
  Downloading pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl (26.2MB)
    100% |████████████████████████████████| 26.3MB 44kB/s 
Collecting numpy>=1.9.0 (from pandas)  
  Downloading numpy-1.14.0-cp36-cp36m-manylinux1_x86_64.whl (17.2MB)
    100% |████████████████████████████████| 17.2MB 58kB/s 
Collecting python-dateutil>=2 (from pandas)  
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 193kB/s 
Collecting pytz>=2011k (from pandas)  
  Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
    100% |████████████████████████████████| 512kB 217kB/s 
Collecting six>=1.5 (from python-dateutil>=2->pandas)  
  Downloading six-1.11.0-py2.py3-none-any.whl
Installing collected packages: numpy, six, python-dateutil, pytz, pandas  
Successfully installed numpy-1.14.0 pandas-0.22.0 python-dateutil-2.6.1 pytz-2017.3 six-1.11.0  

and here is the confirmation that python is installed.


$ python3.6
Python 3.6.4 (default, Jan 13 2018, 12:02:51)  
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.  
>>> import pandas as pd
>>> 

Leave a Reply

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