3
votes

I am using python 2.7.6 and trying to import pandas but Jupyter notebook gives me following

error--

ImportError Traceback (most recent call last) in () ----> 1 import pandas

/usr/local/lib/python2.7/dist-packages/pandas/init.py in () 21 22 # numpy compat ---> 23 from pandas.compat.numpy import * 24 25 try:

/usr/local/lib/python2.7/dist-packages/pandas/compat/numpy/init.py in () 22 'your numpy version is {0}.\n' 23 'Please upgrade numpy to >= 1.9.0 to use ' ---> 24 'this pandas version'.format(_np_version)) 25 26

ImportError: this version of pandas is incompatible with numpy < 1.9.0 your numpy version is 1.8.2. Please upgrade numpy to >= 1.9.0 to use this pandas version

while I have numpy 1.14.1

$ pip freeze
numpy==1.14.1
pandas==0.22.0
pip-magic==0.2.3
python-dateutil==2.6.1
pytz==2018.3
six==1.11.0

I have tried uninstalling and then reinstalling numpy and pandas from ubuntu terminal as well as Jupyter's terminal but unable to solve the error, any help would be appreciated. Thanks.

4
Have you restarted the jupyter notebook after reinstalling the numpy and pandas library?heena bawa
yup but it didnot work.M.Ahsen Taqi

4 Answers

3
votes

I could imagine that you have different versions of Python on your computer. In the Jupyter Notebook try running

import sys
sys.executable

This will show you which Python interpreter is used

EDIT:

You can install a new kernel for jupyter that uses the correct Python interpreter. First get a list of the existing kernels that you have: Type jupyter kernelspec list. If the wanted interpreter is not there you will have to install it. To do so use python -m ipykernel install --name <Kernelname> --display-name <Displayname> Note that the python interpreter you are using to run this command must be the python interpreter that you want to be used by the kernel. Now you are set up! Start a new notebook and you will find that you can choose this new kernel

2
votes

After trying multiple things I was able to resolve it.

The issue here was that python2.7 had older version of numpy i.e. 1.8.2 as the error in the question reports.

In python shell I found the path of numpy in use as follow.

import numpy
print numpy.__path__

the output was this path

/usr/local/lib/python2.7/dist-packages/numpy

went to /usr/local/lib/python2.7/dist-packages and deleted numpy using

sudo rm -r numpy 

then staying in dist-packages directory I installed numpy 1.14.1 simply with pip.

sudo pip install numpy==1.14.1

this solved my problem.

0
votes

One way to make sure that you use the right version or jupyter is the -m option of python:

-m mod : run library module as a script (terminates option list)

If this shows NumPy 1.14:

python -m pip freeze

starting jupyter like this should also give you the same version:

python -m jupyter notebook

you can find what versions of python are on your system and in what order they are searched with:

which -a python
0
votes

Why don't you rm -rf the numpy library and install the version he is asking you too.

sudo pip install numpy==1.14.1