ModuleNotFoundError: No module named pandas, simple fix!
The error “ModuleNotFoundError: No module named pandas» is a common error experienced by data scientists when developing in Python. The error is likely an environment issue whereby the pandas package has not been installed correctly on your machine
The error “ModuleNotFoundError: No module named pandas» is a common error experienced by data scientists when developing in Python. The error is likely an environment issue whereby the pandas package has not been installed correctly on your machine, thankfully there are a few simple steps to go through to troubleshoot the problem and find a solution.
ModuleNotFoundError: No module named pandas
Your error, whether in a Jupyter Notebook or in the terminal, probably looks like one of the following:
No module named ‘pandas’
ModuleNotFoundError: No module named ‘pandas’
- Upgrade pip version
- Upgrade or install pandas package
- Check if you are activating the environment before running
- Create a fresh environment
- Upgrade or install Jupyer Notebook package
Are you installing packages using Conda or Pip package manager?
It is common for developers to use either Pip or Conda for their Python package management. It’s important to know what you are using before we continue with the fix.
If you have not explicitly installed and activated Conda, then you are almost definitely going to be using Pip. One sanity check is to run conda info in your terminal, which if it returns anything likely means you are using Conda.
Upgrade or install pip for Python
First things first, let’s check to see if we have the up to date version of pip installed. We can do this by running:
Upgrade or install pandas package via Conda or Pip
The most common reason for this error is that the pandas package is not installed in your environment or an outdated version is installed. So let’s update the package or install it if it’s missing.
Activate Conda or venv Python environment
It is highly recommended that you use isolated environments when developing in Python. Because of this, one common mistake developers make is that they don’t activate the correct environment before they run the Python script or Jupyter Notebook. So, let’s make sure you have your correct environment running.
For virtual environments:
Create a new Conda or venv Python environment with pandas installed
During the development process, a developer will likely install and update many different packages in their Python environment, which can over time cause conflicts and errors.
Therefore, one way to solve the module error for pandas is to simply create a new environment with only the packages that you require, removing all of the bloatware that has built up over time. This will provide you with a fresh start and should get rid of problems that installing other packages may have caused.
For virtual environments:
Upgrade Jupyter Notebook package in Conda or Pip
If you are working within a Jupyter Notebook and none of the above has worked for you, then it could be that your installation of Jupyter Notebooks is faulty in some way, so a reinstallation may be in order.
Best practices for managing Python packages and environments
- Always use separate environments for your projects and avoid installing packages to your root environment
- Only install the packages you need for your project
- Pin your package versions in your project’s requirements file
- Make sure your package manager is kept up to date
References
Stephen Allwright Twitter
I’m a Data Scientist currently working for Oda, an online grocery retailer, in Oslo, Norway. These posts are my way of sharing some of the tips and tricks I’ve picked up along the way.
No module named pandas что делать
In this article, we will discuss how to fix the No module named pandas error.
The error “No module named pandas ” will occur when there is no pandas library in your environment IE the pandas module is either not installed or there is an issue while downloading the module right.
Let’s see the error by creating an pandas dataframe.
Example: Produce the error
Python3
Output:
We will discuss how to overcome this error. In python, we will use pip function to install any module
Syntax:
So we have to specify pandas
Example: Installing Pandas
Python3
Output:
Collecting pandas
Downloading pandas-3.2.0.tar.gz (281.3 MB)
|████████████████████████████████| 281.3 MB 9.7 kB/s
Collecting py4j==0.10.9.2
Downloading py4j-0.10.9.2-py2.py3-none-any.whl (198 kB)
|████████████████████████████████| 198 kB 52.8 MB/s
Building wheels for collected packages: pandas
Building wheel for pandas (setup.py) … done
Created wheel for pandas: filename=pyspark-3.2.0-py2.py3-none-any.whl size=281805912 sha256=c6c9edb963f9a25f31d11d88374ce3be6b3c73ac73ac467ef40b51b5f4eca737
Stored in directory: /root/.cache/pip/wheels/0b/de/d2/9be5d59d7331c6c2a7c1b6d1a4f463ce107332b1ecd4e80718
Successfully built pandas
Installing collected packages: py4j, pandas
Successfully installed py4j-0.10.9.2 pandas-3.2.0
We can verify by again typing same command then the output will be:
Output:
Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (1.1.5)
To get the pandas description in our environment we can use the show command. This can help keep track of the module and its installation.
ImportError: No module named pandas
I am trying to write code in Python to fetch Twitter data, and I am not getting an error for twython. But I am getting an error for Pandas.
I have installed Pandas using pip install pandas . But I still get the following error. How can I fix it?
13 Answers 13
You’re missing a few (not terribly clear) steps. Pandas is distributed through pip as a wheel, which means you need to do:
You’re probably going to run into other issues after this — it looks like you’re installing on Windows which isn’t the most friendly of targets for NumPy, SciPy, and Pandas. Alternatively, you could pickup a binary installer from here.
You also had an error installing NumPy. Like before, I recommend grabbing a binary installer for this, as it’s not a simple process. However, you can resolve your current error by installing this package from Microsoft.
While it’s completely possible to get a perfect environment setup on Windows, I have found the quality-of-life for a Python developer is vastly improved by setting up a Debian VM. Especially with the scientific packages, you will run into many cases like this.
Troubleshoot No module named Pandas errors in Python
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:
- 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:
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:
- 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.