Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] How to Fix “ImportError: No module named pandas” [Mac/Linux/Windows/PyCharm]

#1
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 pip install pandas. 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 pip install pandas 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:

import pandas as pd

This is supposed to import the Pandas library into your (virtual) environment. However, it only throws the following import error: no module named pandas!

>>> import pandas as pd
ImportError: No module named pandas on line 1 in main.py

You can reproduce this error in the following interactive Python shell:

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 pip. You can run the following command in your Windows shell:

$ pip install pandas

Here’s the screenshot on my Windows machine:

https://blog.finxter.com/wp-content/uplo...00x107.png 300w, https://blog.finxter.com/wp-content/uplo...68x274.png 768w, https://blog.finxter.com/wp-content/uplo...150x54.png 150w, https://blog.finxter.com/wp-content/uplo...mage-9.png 1100w" sizes="(max-width: 1024px) 100vw, 1024px" />

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):

$ python -m pip install --upgrade pip
...
$ pip install pandas

Here’s how this plays out on my Windows command line:

https://blog.finxter.com/wp-content/uplo...300x51.png 300w, https://blog.finxter.com/wp-content/uplo...68x131.png 768w, https://blog.finxter.com/wp-content/uplo...150x26.png 150w, https://blog.finxter.com/wp-content/uplo...age-10.png 1103w" sizes="(max-width: 1024px) 100vw, 1024px" />

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 PyCharm and try to import the Pandas library, it’ll throw the following error:

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 1

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:

https://blog.finxter.com/wp-content/uplo...00x191.png 300w, https://blog.finxter.com/wp-content/uplo...68x490.png 768w, https://blog.finxter.com/wp-content/uplo...150x96.png 150w, https://blog.finxter.com/wp-content/uplo...age-12.png 1108w" sizes="(max-width: 1024px) 100vw, 1024px" />

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 pandas text in your editor:

https://blog.finxter.com/wp-content/uplo...00x192.png 300w, https://blog.finxter.com/wp-content/uplo...68x492.png 768w, https://blog.finxter.com/wp-content/uplo...150x96.png 150w, https://blog.finxter.com/wp-content/uplo...age-14.png 1102w" sizes="(max-width: 1024px) 100vw, 1024px" />

Second, click “Show Context Actions” 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.



https://www.sickgaming.net/blog/2020/11/...s-pycharm/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tut] How Does Pandas Concat Work? xSicKxBot 0 8 11-23-2020, 09:03 AM
Last Post: xSicKxBot
  [Tut] How to Create a DataFrame in Pandas? xSicKxBot 0 30 11-14-2020, 01:31 AM
Last Post: xSicKxBot
  [Tut] Pandas NaN — Working With Missing Data xSicKxBot 0 30 11-05-2020, 02:44 AM
Last Post: xSicKxBot
  [Tut] Writing, Running, Debugging, and Testing Code In PyCharm xSicKxBot 0 26 11-02-2020, 10:16 PM
Last Post: xSicKxBot
  [Tut] A Simple Recommendation System With Pandas xSicKxBot 0 23 10-31-2020, 06:58 AM
Last Post: xSicKxBot
  [Tut] Python Math Module [Ultimate Guide] xSicKxBot 0 147 06-04-2020, 02:36 AM
Last Post: xSicKxBot
  [Tut] Python Math Module [Ultimate Guide] xSicKxBot 0 150 05-27-2020, 05:44 AM
Last Post: xSicKxBot
  [Tut] Tilde Python Pandas DataFrame xSicKxBot 0 155 05-17-2020, 06:40 AM
Last Post: xSicKxBot
  [Tut] Pandas to_csv() xSicKxBot 0 195 04-30-2020, 03:56 AM
Last Post: xSicKxBot
  [Tut] [PDF Collection] 7 Beautiful Pandas Cheat Sheets — Post Them to Your Wall xSicKxBot 0 251 04-29-2020, 03:23 AM
Last Post: xSicKxBot

Forum Jump:

[-]
Active Threads
[Tut] list.clear() vs New List — Why Cle...
Last Post: xSicKxBot
Yesterday 09:53 PM
» Replies: 0
» Views: 2
News - Poll: Box Art Brawl: Duel #69 – T...
Last Post: xSicKxBot
Yesterday 09:10 PM
» Replies: 0
» Views: 2
News - Video: The Nintendo Life Holiday ...
Last Post: xSicKxBot
Yesterday 09:10 PM
» Replies: 0
» Views: 2
News - Darth Vader Actor David Prowse Pa...
Last Post: xSicKxBot
Yesterday 09:09 PM
» Replies: 0
» Views: 5
(Indie Deal) FREE Brigade E5, Big Bandai...
Last Post: xSicKxBot
Yesterday 07:40 PM
» Replies: 0
» Views: 2
News - Fall Guys developer Mediatonic op...
Last Post: xSicKxBot
Yesterday 05:36 PM
» Replies: 0
» Views: 4
News - Tinybuild sinks $3 million into S...
Last Post: xSicKxBot
Yesterday 05:36 PM
» Replies: 0
» Views: 3
News - Nintendo Shares Tips On How To Ke...
Last Post: xSicKxBot
Yesterday 02:43 PM
» Replies: 0
» Views: 2
News - Random: Amateur Dev Releases Reim...
Last Post: xSicKxBot
Yesterday 02:43 PM
» Replies: 0
» Views: 2
[Tut] Python abs() Function
Last Post: xSicKxBot
Yesterday 09:45 AM
» Replies: 0
» Views: 5

[-]
Twitter

[-]
Sponsored
Get the Deal of the Week at RefurBees.com

Copyright © SickGaming.net 2012-2020