Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter python3 notebook cannot recognize pandas

I am using the Jupyter notebook with Python 3 selected. On the first line of a cell I am entering:

import pandas as pd 

The error I get from the notebook is, ImportError: No module named 'pandas'. How can I install pandas to the jupyter notebook? The computer I launched the Jupyter notebook from definitely has pandas.

I tried doing:

!pip install pandas 

And it says it is already installed but for Python 2.7 at the bottom. My script shows it is a Python 3 script at the top though.

When I do echo $PATH in Ubuntu is shows that '/home/user/anaconda2/bin' is on the first entry. I think I may need to change this to be anaconda3?

UPDATE: When I try and launch a Python3 script through jupyter the command line which launched Jupyter gives me the error "ImportError: No module named 'IPython.paths'. Then there is a timeout waiting for 'kernel_info' reply. Additionally, I tried removing anaconda but still experience the same error. I have tried to make so many quick fixes now, that I am not sure what the next step is to get this working.

like image 848
William Ross Avatar asked Nov 11 '16 17:11

William Ross


People also ask

Why is pandas not working in Python?

In most cases this error in Python generally raised: You haven't installed Pandas explicitly with pip install pandas. You may have different Python versions on your computer and Pandas is not installed for the particular version you're using.

Does Jupyter notebook support pandas?

In JupyterLab, create a new (Python 3) notebook: In the first cell of the notebook, you can import pandas and check the version with: Now you are ready to use pandas, and you can write your code in the next cells.


2 Answers

As your default python version is 2.x , if you don't have any emphasis on the python 3.x you can try from the first by the below scripts.

pip install --upgrade pip pip install jupyter 

then in jupyter notebook:

!pip install pandas 

The version of notebook will be 2.x. Otherwise install pip3 by the below Linux commands.

sudo apt-get install python3-setuptools sudo easy_install3 pip 

now you can add pandas to the notebook by !pip3 install pandas.

like image 169
amin Avatar answered Oct 08 '22 01:10

amin


This worked for me

  1. in Jupiter notebook

     import sys  print(sys.executable)  
  2. copy path eg:

      /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 
  3. install the module on the terminal like this.

     /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install pandas 

Or it can be installed directly from Jupyter Cell as follows

! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install pandas 
like image 31
Samuel S. Ampofo Avatar answered Oct 08 '22 00:10

Samuel S. Ampofo