How To Fix ModuleNotFoundError: No Module Named ‘pandas’ In Python

ModuleNotFoundError: No module named 'pandas' in Python

If you get the error ModuleNotFoundError: No module named ‘pandas’ in Python and don’t know what to do, I have a few suggestions for installing the pandas module for you. Read the article below to learn more.

What causes the ModuleNotFoundError: No module named ‘pandas’ in Python?

The ModuleNotFoundError: No module named ‘pandas’ error happens because you have not installed the ‘pandas’ module to use or you installed the wrong environment. I will do the installation in a virtual environment.

How to solve this error?

Install library ‘pandas’ 

Install the ‘pandas’ module. You can use Python pip. But note that you need to specify the exact version of Python you are using.

Example:

If you don’t have pip installed here is the solution for you in Python 3:

python3 -m pip install pandas

If you use Python 3, use the pip3 statement as follows:

pip3 install pandas

If you use Python 2, use the following pip command:

pip install pandas

Install ‘pandas’ on operating systems

I would install ‘pandas’ according to your operating system.

Install ‘pandas’ on Windows using pip

Before installing ‘pandas’, you need to create a virtual environment. Using a virtual environment helps you avoid incompatibilities between packages and break the system if you install incompatible libraries with your operating system.

You can activate the virtual environment with the following command:

venv\Scripts\Activate.ps1

Then you can install the ‘pandas’ module with the following command:

python3 -m pip install pandas 

If you do not have pip installed, use the following command:

python3 -m pip install pandas

Install ‘pandas’ on Mac using pip

Make sure you have installed Python and pip. Just like on Windows operating systems, you also need a virtual environment. Just like on Windows operating systems, you also need your virtual environment. You can activate the virtual environment with the following command:

source venv/bin/activate

Install ‘pandas’ in the command prompt environment:

python3 -m pip install pandas

Install module ‘pandas’ by Anaconda

Anaconda is the most popular open-source Data Science platform available on Python. Install Anaconda first, create a virtual environment, and install ‘pandas’.

To create an anaconda environment:

conda create -n pandas python=3.8

Enable the project area you will see ‘pandas’ in parentheses next to the line prompt:

source activate pandas

Finally, install ‘pandas’ with the command:

conda install -c anaconda pandas

Import pandas module

Once you have successfully installed the pandas module, to use it, you need to import this module with the following syntax:

import pandas as pd
import pandas

Summary

That’s how I figured out how to solve the ModuleNotFoundError: No module named ‘pandas’ in Python. Hopefully, this article can help you. If you have any ideas or better ways, please comment below. Thanks for reading!

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *