{"id":120369,"date":"2020-11-07T15:26:38","date_gmt":"2020-11-07T15:26:38","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=16569"},"modified":"2020-11-07T15:26:38","modified_gmt":"2020-11-07T15:26:38","slug":"how-to-fix-importerror-no-module-named-pandas-mac-linux-windows-pycharm","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2020\/11\/07\/how-to-fix-importerror-no-module-named-pandas-mac-linux-windows-pycharm\/","title":{"rendered":"How to Fix \u201cImportError: No module named pandas\u201d [Mac\/Linux\/Windows\/PyCharm]"},"content":{"rendered":"<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>Quick Fix:<\/strong> Python throws the <em>&#8220;ImportError: No module named pandas&#8221;<\/em> when it cannot find the Pandas installation. The most frequent source of this error is that you haven&#8217;t installed Pandas explicitly with <code>pip install pandas<\/code>. Alternatively, you may have different Python versions on your computer and Pandas is not installed for the particular version you&#8217;re using. To fix it, run <code>pip install pandas<\/code> in your Linux\/MacOS\/Windows terminal. <\/p>\n<p><strong>Problem<\/strong>: You&#8217;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:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd<\/pre>\n<p>This is supposed to import the Pandas library into your <a href=\"https:\/\/blog.finxter.com\/python-virtual-environments-with-venv-a-step-by-step-guide\/\" title=\"Python Virtual Environments with \u201cvenv\u201d \u2014 A Step-By-Step Guide\" target=\"_blank\" rel=\"noreferrer noopener\">(virtual) environment<\/a>. However, it only throws the following import error: no module named pandas!<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> import pandas as pd\nImportError: No module named pandas on line 1 in main.py<\/pre>\n<p>You can reproduce this error in the following interactive Python shell:<\/p>\n<p> <iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python\/0fccab1ed2\" width=\"100%\" height=\"356\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe> <\/p>\n<p><strong><em>Why did this error occur? <\/em><\/strong><\/p>\n<p>The reason is that Python doesn&#8217;t provide Pandas in its standard library. You need to install Python first!<\/p>\n<p>Before being able to import the Pandas module, you need to install it using Python&#8217;s package manager <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">pip<\/code>. You can run the following command in your Windows shell:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ pip install pandas<\/pre>\n<p>Here&#8217;s the screenshot on my Windows machine:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"366\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-9-1024x366.png\" alt=\"\" class=\"wp-image-16576\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-9-1024x366.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-9-300x107.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-9-768x274.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-9-150x54.png 150w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-9.png 1100w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>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&#8217;t, use the following two commands (there&#8217;s no harm in doing it anyways):<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ python -m pip install --upgrade pip\n...\n$ pip install pandas<\/pre>\n<p>Here&#8217;s how this plays out on my Windows command line:<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"175\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-10-1024x175.png\" alt=\"\" class=\"wp-image-16577\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-10-1024x175.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-10-300x51.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-10-768x131.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-10-150x26.png 150w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-10.png 1103w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<p>The warning message disappeared!<\/p>\n<p>If you need to refresh your Pandas skills, check out the following Pandas cheat sheets&#8212;I&#8217;ve compiled the best 5 in this article.<\/p>\n<p><strong>Related article:<\/strong> <a href=\"https:\/\/blog.finxter.com\/pandas-cheat-sheets\/\" title=\"[PDF Collection] 7 Beautiful Pandas Cheat Sheets \u2014 Post Them to Your Wall\">Top 5 Pandas Cheat Sheets<\/a><\/p>\n<h2>How to Fix &#8220;ImportError: No module named pandas&#8221; in PyCharm<\/h2>\n<p>If you create a new Python project in <a href=\"https:\/\/blog.finxter.com\/pycharm-a-simple-illustrated-guide\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"PyCharm \u2013 A Simple Illustrated Guide\">PyCharm <\/a>and try to import the Pandas library, it&#8217;ll throw the following error:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Traceback (most recent call last): File \"C:\/Users\/xcent\/Desktop\/Finxter\/Books\/book_dash\/pythonProject\/main.py\", line 1, in &lt;module> import pandas as pd\nModuleNotFoundError: No module named 'pandas' Process finished with exit code 1<\/pre>\n<p>The reason is that each PyCharm project, per default, creates a <a href=\"https:\/\/blog.finxter.com\/python-virtual-environments-conda\/\" title=\"Python Virtual Environments with Conda \u2014 Why the Buzz?\" target=\"_blank\" rel=\"noreferrer noopener\">virtual environment<\/a> in which you can install custom Python modules. But the virtual environment is initially empty&#8212;even if you&#8217;ve already installed Pandas on your computer!<\/p>\n<p>Here&#8217;s a screenshot:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"653\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-1024x653.png\" alt=\"\" class=\"wp-image-16587\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-1024x653.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-300x191.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-768x490.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-150x96.png 150w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12.png 1108w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>The fix is simple: Use the PyCharm installation tooltips to install Pandas in your virtual environment&#8212;two clicks and you&#8217;re good to go!<\/p>\n<p>First, right-click on the <code>pandas<\/code> text in your editor:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"656\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-1024x656.png\" alt=\"\" class=\"wp-image-16593\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-1024x656.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-300x192.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-768x492.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-150x96.png 150w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14.png 1102w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>Second, click &#8220;<code>Show Context Actions<\/code>&#8221; in your context menu. In the new menu that arises, click &#8220;Install Pandas&#8221; and wait for PyCharm to finish the installation. <\/p>\n<p>The code will run after your installation completes successfully. <\/p>\n<p>Here&#8217;s a complete introduction to PyCharm:<\/p>\n<p><strong>Related Article:<\/strong><a href=\"https:\/\/blog.finxter.com\/pycharm-a-simple-illustrated-guide\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"PyCharm \u2013 A Simple Illustrated Guide\"> PyCharm&#8212;A Helpful Illustrated Guide<\/a><\/p>\n<p>The post <a href=\"https:\/\/blog.finxter.com\/how-to-fix-importerror-no-module-named-pandas\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Fix &#8220;ImportError: No module named pandas&#8221; [Mac\/Linux\/Windows\/PyCharm]<\/a> first appeared on <a href=\"https:\/\/blog.finxter.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Finxter<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick Fix: Python throws the &#8220;ImportError: No module named pandas&#8221; when it cannot find the Pandas installation. The most frequent source of this error is that you haven&#8217;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&#8217;re [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-120369","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/120369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=120369"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/120369\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=120369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=120369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=120369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}