pandas: pandas not found when it's supposed to be installed

I got this error message. Already installed pandas.

>>> import pandas as pd
Traceback (most recent call last):
  File "analyze_tweets.py", line 9, in <module>
    import pandas as pd 
ImportError: No module named pandas

SOLUTION (by @datapythonista)

This error happens when Python can’t find pandas in the list of available libraries. Python has internally a list of directories where it’ll look for packages. These directories can be obtained with import sys; sys.path.

In one machine you can (and should) have several Python installations. Meaning that you can have pandas installed in one, and be using another Python installation (this is likely the case here).

In Linux/Mac you can run which python and will tell you which is the Python you’re using. If it’s something like /usr/bin/python, you’re using the Python from the system, which is not a great practice, and rarely used in the Python community.

If you used Python before you may have used virtual environments and pip. While this is fine for many Python projects (e.g. Django), when using data projects (pandas, numpy, tensorflow…) this is discouraged. It’s easy that you have installation errors, and also the libraries can run much slower when using pip.

The widely used solution to this problem is to use conda. You can find simple installation instructions for pandas in this document: https://dev.pandas.io/getting_started.html

For more advanced users, installing miniconda, and then manually install pandas (and any other required package) with conda can be preferred (but avoid this if you’re starting, since you’ll probably have errors of missing dependencies when using many of the pandas features).

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 27 (8 by maintainers)

Most upvoted comments

same answer. you probably have multiple pythons installed. pls read the installation instructions and follow them.

if you can’t import it then its not installed. and you shouldn’t be pathing at all. this indicates a problem with how you installed things.

edit from @TomAugspurger: Don’t use sudo pip install

@datomnurdin @scls19fr @AMFIRNAS

sudo pip3 install pandas

try that it worked for me.

edit from @TomAugspurger: Don’t use sudo pip install.

You can check my output message here after I run sudo pip install pandas.

sudo pip install pandas
Requirement already satisfied (use --upgrade to upgrade): pandas in /usr/lib64/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in /usr/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.0 in /usr/lib64/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /usr/lib/python2.7/site-packages (from python-dateutil->pandas)

My problem resolved by using pip3 install pandas. Python version was 3.5.*.

edit from @TomAugspurger: don’t use sudo pip install

for python 2:

sudo pip2 install pandas

sudo pip3 install pandas

The original issue is for Python 2.x, so unfortunately, this suggestion is moot. On Linux, do the following:

which python
which pip

and see where each is pointing to. Something tells me you’ll find a discrepancy. If not, chase down where your “existing” pandas installation is located and see whether it is actually installed there.

I fixed the same problem with the below commands… Type python on your terminal. If you see python version 2.x then run these two commands to install pandas: sudo python -m pip install wheel and sudo python -m pip install pandas. Else if you see python version 3.x then run these two commands to install pandas: sudo python3 -m pip install wheel and sudo python3 -m pip install pandas. Good Luck!

I am facing the following issue in my code:

`ImportError Traceback (most recent call last) <ipython-input-1-20d62f942773> in <module>() ----> 1 import pandas as pd 2 3 import numpy as np 4 5 import matplotlib.pyplot as plt

ImportError: No module named pandas`

Even though I have installed pandas.

I am using Jupyter notebook.