11-08-2020, 01:36 AM
How to Fix “ImportError: No module named pandas” [Mac/Linux/Windows/PyCharm]
Quick Fix: Python throws the “ImportError: No module named pandas” when it cannot find the Pandas installation. The most frequent source of this error is that you haven’t installed Pandas explicitly with. Alternatively, you may have different Python versions on your computer and Pandas is not installed for the particular version you’re using. To fix it, run in your Linux/MacOS/Windows terminal.
Problem: You’ve just learned about the awesome capabilities of the Pandas library and you want to try it out, so you start with the following import statement you found on the web:
This is supposed to import the Pandas library into your (virtual) environment. However, it only throws the following import error: no module named pandas!
You can reproduce this error in the following interactive Python shell:
https://trinket.io/embed/python/0fccab1ed2
Why did this error occur?
The reason is that Python doesn’t provide Pandas in its standard library. You need to install Python first!
Before being able to import the Pandas module, you need to install it using Python’s package manager. You can run the following command in your Windows shell:
Here’s the screenshot on my Windows machine:
![[Image: image-9-1024x366.png]](https://blog.finxter.com/wp-content/uploads/2020/11/image-9-1024x366.png)
This simple command installs Pandas in your virtual environment on Windows, Linux, and MacOS. It assumes that you know that your pip version is updated. If it isn’t, use the following two commands (there’s no harm in doing it anyways):
Here’s how this plays out on my Windows command line:
![[Image: image-10-1024x175.png]](https://blog.finxter.com/wp-content/uploads/2020/11/image-10-1024x175.png)
The warning message disappeared!
If you need to refresh your Pandas skills, check out the following Pandas cheat sheets—I’ve compiled the best 5 in this article.
Related article: Top 5 Pandas Cheat Sheets
How to Fix “ImportError: No module named pandas” in PyCharm
If you create a new Python project in PyCharmand try to import the Pandas library, it’ll throw the following error:
The reason is that each PyCharm project, per default, creates a virtual environment in which you can install custom Python modules. But the virtual environment is initially empty—even if you’ve already installed Pandas on your computer!
Here’s a screenshot:
![[Image: image-12-1024x653.png]](https://blog.finxter.com/wp-content/uploads/2020/11/image-12-1024x653.png)
The fix is simple: Use the PyCharm installation tooltips to install Pandas in your virtual environment—two clicks and you’re good to go!
First, right-click on the text in your editor:
![[Image: image-14-1024x656.png]](https://blog.finxter.com/wp-content/uploads/2020/11/image-14-1024x656.png)
Second, click “” in your context menu. In the new menu that arises, click “Install Pandas” and wait for PyCharm to finish the installation.
The code will run after your installation completes successfully.
Here’s a complete introduction to PyCharm:
Related Article:PyCharm—A Helpful Illustrated Guide
The post How to Fix “ImportError: No module named pandas” [Mac/Linux/Windows/PyCharm] first appeared on Finxter.
Quick Fix: Python throws the “ImportError: No module named pandas” when it cannot find the Pandas installation. The most frequent source of this error is that you haven’t installed Pandas explicitly with
Code:
pip install pandasCode:
pip install pandasProblem: You’ve just learned about the awesome capabilities of the Pandas library and you want to try it out, so you start with the following import statement you found on the web:
Code:
import pandas as pdThis is supposed to import the Pandas library into your (virtual) environment. However, it only throws the following import error: no module named pandas!
Code:
>>> import pandas as pd
ImportError: No module named pandas on line 1 in main.pyYou can reproduce this error in the following interactive Python shell:
https://trinket.io/embed/python/0fccab1ed2
Why did this error occur?
The reason is that Python doesn’t provide Pandas in its standard library. You need to install Python first!
Before being able to import the Pandas module, you need to install it using Python’s package manager
Code:
pipCode:
$ pip install pandasHere’s the screenshot on my Windows machine:
![[Image: image-9-1024x366.png]](https://blog.finxter.com/wp-content/uploads/2020/11/image-9-1024x366.png)
This simple command installs Pandas in your virtual environment on Windows, Linux, and MacOS. It assumes that you know that your pip version is updated. If it isn’t, use the following two commands (there’s no harm in doing it anyways):
Code:
$ python -m pip install --upgrade pip
...
$ pip install pandasHere’s how this plays out on my Windows command line:
![[Image: image-10-1024x175.png]](https://blog.finxter.com/wp-content/uploads/2020/11/image-10-1024x175.png)
The warning message disappeared!
If you need to refresh your Pandas skills, check out the following Pandas cheat sheets—I’ve compiled the best 5 in this article.
Related article: Top 5 Pandas Cheat Sheets
How to Fix “ImportError: No module named pandas” in PyCharm
If you create a new Python project in PyCharmand try to import the Pandas library, it’ll throw the following error:
Code:
Traceback (most recent call last): File "C:/Users/xcent/Desktop/Finxter/Books/book_dash/pythonProject/main.py", line 1, in <module> import pandas as pd
ModuleNotFoundError: No module named 'pandas' Process finished with exit code 1The reason is that each PyCharm project, per default, creates a virtual environment in which you can install custom Python modules. But the virtual environment is initially empty—even if you’ve already installed Pandas on your computer!
Here’s a screenshot:
![[Image: image-12-1024x653.png]](https://blog.finxter.com/wp-content/uploads/2020/11/image-12-1024x653.png)
The fix is simple: Use the PyCharm installation tooltips to install Pandas in your virtual environment—two clicks and you’re good to go!
First, right-click on the
Code:
pandas![[Image: image-14-1024x656.png]](https://blog.finxter.com/wp-content/uploads/2020/11/image-14-1024x656.png)
Second, click “
Code:
Show Context ActionsThe code will run after your installation completes successfully.
Here’s a complete introduction to PyCharm:
Related Article:PyCharm—A Helpful Illustrated Guide
The post How to Fix “ImportError: No module named pandas” [Mac/Linux/Windows/PyCharm] first appeared on Finxter.

