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, VSCode 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 the 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 installed in your Python development environment.
If you get such an error, you 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):
- First off, ensure that you work has been saved and close your Python development environment.
- Then, hit the Windows key or the magnifying glass in your taskbar, and type cmd.
- Hit Enter
- The command prompt will open.
- Go ahead and type:
pip install pandas
- Hit Enter.
- Python will download the pandas library from the online repository.
- Once done, type exit followed by Enter to close your command prompt.
- Open your Python development environment and open your Python script or Notebook.
- 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
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.
- Hit the Windows button or magnifying glass icon (alternatively, hit the Windows key + S).
- Type Anaconda Prompt and hit the Enter key.
- First off, we’ll activate the environment so we can modify it.
- Type conda activate <full_environment_path> then hit Enter.
- Then instead of using PIP we’ll type:
conda install pandas
- Hit Enter.
- pandas will be installed in your MiniConda package folder.
- Close the Anaconda Prompt.
- 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.