How to pip install pandas to fix not found or import errors?

When setting up our Python data analysis environments on Windows, MAC or Linux and getting started with our coding we might encounter import errors.
These errors originate from the fact that specific packages we call in our Python code (wrote using Jupyter Lab or Notebooks, Spyder, PyCharm or other development environment your might be using) are simply not available in our computers.
In today’s example we’ll focus on troubleshooting Pandas modulenotfound errors, but the procedure below is similar for any Python package, including the Data Analysis related ones such as Numpy, Seaborn, matplotlib and others.

You might be receiving two types of errors; we typically troubleshoot them in similar ways:

  • modulenotfounderror: no module named ‘pandas’,
  • importerror: no module named pandas

Solving importerror:no module named ‘pandas’

As mentioned above, if you are receiving this error or the modulenotfound error; it’s very likely that the pandas library is not available in your Python install.

If you get such an error we can easily solve it with the Python pip utility. Kindly proceed as following (the tutorial below assumes that you have an internet connection available and that you are using Windows).

  1. First off, ensure that you work has been saved and close your Python development environment.
  2. Then, hit the Windows key or the magnifying glass in your taskbar, and type cmd.
  3. Hit Enter
  4. The command prompt will open.
  5. Go ahead and type:
pip install pandas
  1. Hit Enter.
  2. Python will download the pandas library from the online repository.
  3. Once done, type exit followed by Enter to close your command prompt.
  4. Open your Python development environment and open your Python script or Notebook.
  5. Re-run your code.

You should be all-set. You can even verify your pandas package version by typing the gollowing command followed by Enter:

import pandas as pd
pd.__version__

In my case, the version i currently use is

'1.1.2'

Troubleshoot pandas modulenotfounderror on MiniConda or Anaconda

If you are using Anaconda, you are less likely to encounter import errors, as pandas is part of the default Anaconda delivery.

If you are using MiniConda, you might need to employ a few extra steps.

  1. Hit the Windows button or magnifying glass icon.
  2. Type Anaconda Prompt and hit Enter.
  3. First off, we’ll activate the environment so we can modify it.
  4. Type conda activate <full_environment_path> then hit Enter.
  5. Then instead of using PIP we’ll type:
conda install pandas
  1. Hit Enter.
  2. pandas will be installed in your MiniConda package folder.
  3. Close the Anaconda Prompt.
  4. Open your Python Notebook / Script.

Follow up reading: encountering errors when trying to use the requests module? Here’s how to install requests in Python if an import error is found.