简体   繁体   中英

Pandas not working even though its installed

I've installed python and pandas using the Anaconda library, but it doesn't work when I try to import pandas in Jupyter Notebook or in the Python Idle. It does work when I run the shell in the terminal.

I am using macOS Mojave and Python version 3.7.6.

In the terminal, it says I have pandas already installed as you can see below.

在此处输入图像描述

However, I get the error message "ModuleNotFoundError: No module named 'pandas'" when trying to import it in the Python Idle as you can see below.

在此处输入图像描述

I think I know where the problem comes from but I don't know how to troubleshoot or fix it. I installed Anaconda 2 years ago and used it but deleted it when I was done with it to make space in my computer and now I reinstalled it. So I think the Idle and Jupyter Notebook are using a different version of Python than the one that came in the Anaconda package. I might be completely wrong.

Thank you for your help!

You probably haven't installed pandas in the same environment your Jupyter kernel is running in.

You can install it directly from Jupyter notebook by running !pip install pandas . That will install it in the environment that the kernel started in.

In general, running !pip freeze from jupyter notebook should show you all installed libraries. If pandas is not there after you ran !pip install pandas , your environment paths are broken in some big way.

In that case, I'd suggest nuking anaconda and jupyter installation and starting again.

If you want to know more about kernels and how packages work in them https://biasandvariance.com/importing-packages-in-jupyter-notebook/ could help.

If you want to use Anaconda, then just do:

conda install pandas

Mixing conda and pip may cause issues.

Can you try updating pandas?

pip install --upgrade pandas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM