Jupyter python3 notebook cannot recognize pandas

Question:

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.

Asked By: William Ross

||

Answers:

If pip3 is install you could run

!pip3 install pandas
Answered By: Axel Juraske

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.

Answered By: amin

If you use anaconda already as a distribution, stop using pip in that context. Use conda instead and you will stop having headaches. The command lines and procedures for setting up a new environment are pretty well documented here.

Basically upgrading python or having specific branches:

conda update python
conda install python=3.5

Or using specific environments:

conda create -n py35 python=3.5 anaconda
Answered By: Zeugma

This is what i have done in my system:

I have installed both anaconda for python 2.7 and anaconda for python 3.5. Anaconda helps keep both the environment separate.

In Ubuntu:

The directory structure is like this:
anaconda2/bin/
anaconda3/bin/

Whenever i want to use python 2.7 i go to anaconda2/bin/ and create an environment or activate already existing environment and install or import all the necessary packages and same goes for python3.5 (go to anconda3/bin/ create or activate the required environment). This helps me keep things separate.

Since you are using anaconda you should first use “conda install ” if that package is not found, then you can use pip install .

In Windows:

If you install both anaconda2 and anaconda3, its quite easy..
the shortcuts for anaconda prompt are in C:Usersyour-username

there will be two folders anconda2 and anaconda3, you can start conda prompt for python2.7 from anaconda2 and python3.5 from anconda3

So, once you start the anaconda prompt you can just type “jupyter notebook” to open jupyter notebook in browser and import pandas(or any package).

You can check this link:

http://conda.pydata.org/docs/test-drive.html#managing-conda

Answered By: Yaman Ahlawat

Iuse window 7 for work and I had the same problems when I tried to import Pandas. So I tried to install packages under each environment:

Run cmd and type the following code:

activate py27 
conda install pandas 

If the system asks you do you want to install the following new packages, choose Y for [yes]

And install pandas for each different environment if you installed Python27, Python 35 and Python 36, as I did.

Then problem solved if you run jupyter notebook again and you can import pandas successfully.

You can also solve the same problem for packages like numpy, scipy, etc..

Answered By: Helen Xiaoqin Yi

Maybe its a broken (pip) installation. Following worked for me:

sudo apt –fix-broken install

Followed by:

sudo pip3 install pandas

Hope this helps.

Answered By: tilakmukul

I meet the same problem in jupyter notebook, and I run the command below and solve my problem:

!pip install pandas
Answered By: zhao

I was getting the error

modulenotfounderror: no module named ‘pandas’

in jupyter.
I tried the command:

!pip install pandas

and it worked like a charm.

Answered By: Santosh sanwal

simple step to resolve the problem is

( NOTE: Remember what you have selected python 2 or python 3).

for python 2+

!pip install pandas

or if you have user permission error type

!pip install pandas --user

for python 3+

!pip3 install pandas

or if you have user permission error type

!pip3 install pandas --user
Answered By: Abdullah Akhtar

For Windows

The first step is to create a new conda environment. A conda environment is like a virtualenv that allows you to specify a specific version of Python and set of libraries. Run the following commands from a terminal window:

conda create -n name_of_my_env python

This will create a minimal environment with only Python installed in it. To put your self inside this environment run:

source activate name_of_my_env

On Windows the command is:

activate name_of_my_env

The final step required is to install pandas. This can be done with the following command:

conda install pandas

To install a specific pandas version:

conda install pandas=0.20.3

To install other packages, IPython for example:

conda install ipython

To install the full Anaconda distribution:

conda install anaconda

If you need packages that are available to pip but not conda, then install pip, and then use pip to install those packages:

conda install pip
pip install django
Answered By: Abdullah Akhtar

My pandas version was 0.20.3 I have updated to 0.25 using conda update pandas. I have checked in Command Line Interface(CLI) its pd.__version__ '0.25.1'.

In Jupyter notebook its showing ‘0.20.3’.

Please restart jupyter notebook. note is cache your pandas. or you can create a new notebook

Answered By: user6882757

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
Answered By: Samuel S. Ampofo

Simple solution : In a Notebook’s cell type and execute the code:

import sys  
!{sys.executable} -m pip install pandas
Answered By: Aniket Malik

One silly mistake that you could make is to invoke Jupyter with your local machine
python installation and not the anaconda python. I had the same problem and just
setting the PATH did not work for me.

FIX: By default, anaconda binaries are in "<Path_to_anaconda>/bin". For example, in my case, they are in "/home/klakhotia/anaconda3/bin". This directory will also contain the binary to anaconda jupyter. Launch the jupyter from here or create an alias in your .bashrc that points to this file.

Answered By: User2332

What worked for me was:

pip3 install pandas jupyter
Answered By: Adam Ciesielski