ModuleNotFoundError: No module named 'pandas' (jupyter notebook)

Viewed 20149

I don't understand how to install modules to Jupyter Notebook. I tried importing different frameworks but nothing can be imported even though I have everything installed in my system. I'm using pip.

Or maybe there's a way to point Jupyter to a certain virtualenv?

6 Answers
import sys
!{sys.executable} -m pip install pandas

Packages are usually installed using pip. You can use pip in many ways, such as :

  1. Directly in your jupyter notebook by writing the following command:

    !pip install pandas

this will save/install pandas in your default system path.

  1. Using command prompt

    pip install pandas

For this, you need to make sure that the path where pandas is being installed is same as your system path (read default path) in jupyter notebook

In case, You already have Pandas in your system and still not able to load it then it might be due to location/path of your package not defined in jupyter.You need to set the system path where your pandas package reside, you can use sys package to add the path of your package:

import sys
sys.path.append('your-path')

'your-path' is the location of pandas package on your system

If you are working in a virtualenv and you installed jupyter outside of virtualenv then jupyter-notebook couldn't recognize the packages that you've installed inside virtualenv.

You've to first install jupyter inside virtualenv i.e by first activating your virtualenv and then installing your jupyter by:

pip install jupyter

and then install your pandas package by:

pip install pandas

Hope this works!

I just met the same situation tonight, but the answers above did not solve my confusion.

What confused me is, I have everything right installed already. When I check in the Termianl, I can do "import pandas" perfectly. But when in Jupyter, it only gets ModuleNotFoundError.

Then I opened the terminal provided by Jupyter, I realized that I had two versions of python installed, python 3.7 and 3.8. When in system's terminal, python3 command will go to python 3.8. But the Jupyter is installed under python 3.7. Therefore if you want to work all right under Jupyter, you have to install everything (again) under python 3.7. You can do it either in terminal or in Jupyter. Open any notepage, and install using pip commands just like they said (check the other answers).

OR, you can simply remove the unnecessary verion of python, which is what I did. I removed the python 3.7. and reinstalled jupyter under python 3.8.

Now everything works.

So if you met the same ModuleNotFoundError but the moudle actually was installed, you may check the version of python carefully.

Hope my experience helps.

If you are getting 'permission denied' error using:

pip install pandas

try typing this in a terminal:

pip install pandas --user

This will install the library to the 'Python user install directory for your platform' which should not require admin rights to read or write to. For more details type:

pip install --help

This works for me. Type this code in a Jupyter cell.

!pip install pandas
Related