import pandas as pd ImportError: No module named pandas
Asked Answered
V

9

6

I can't seem to import panda package. I use Visual Studio code to code. I use a mac and have osX 10.14 Majove.

The code that i am trying to compile is :

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
house_data = pd.read_csv('house.csv')
plt.plot(house_data['surface'], house_data['loyer'], 'ro', markersize=4)
plt.show()

When I try to use pip install pandas i get on my terminal :

(base)  pip install pandas
Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.24.0)
Requirement already satisfied: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)
Requirement already satisfied: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)
Requirement already satisfied: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)
Requirement already satisfied: six>=1.5 in /Users/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)
(base) Thibaults-MBP-5d47:ML_folder thibaultmonsel$

Then when i execute my code i get :

Traceback (most recent call last):
  File "ML1.py", line 5, in <module>
    import pandas as pd
ImportError: No module named pandas

After if i try sudo pip install pandas i get :

(base) MBP-5d47:ML_folder $ sudo pip3 install pandas --upgrade
Password:
The directory '/Users/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory.If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/34/63/529fd1391044051514f2f22d61754245db2133cd37c4dad7150a1cbe2ece/pandas-0.24.1-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (15.9MB)
    100% |████████████████████████████████| 15.9MB 901kB/s
Requirement already satisfied, skipping upgrade: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)
Requirement already satisfied, skipping upgrade: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)
Requirement already satisfied, skipping upgrade: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)
Requirement already satisfied, skipping upgrade: six>=1.5 in /Users/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)
Installing collected packages: pandas
  Found existing installation: pandas 0.24.0
    Uninstalling pandas-0.24.0:
      Successfully uninstalled pandas-0.24.0
Successfully installed pandas-0.24.1

However, i still get no modules named pandas

Lastly, when i try pip3 install pandas i get :

Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.24.0)
Requirement already satisfied: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)
Requirement already satisfied: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)
Requirement already satisfied: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)
Requirement already satisfied: six>=1.5 in /Users/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)

When i try to execute the program i get the same error mentioned above after using pip3 install pandas....

I also did an import.sys if can help :

base)-MBP-5d47:ML_folder $ python help1.py
2.7.10 (default, Aug 17 2018, 17:41:52)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)]

Here is also my sys.path :

['/Users/Desktop/ML_folder', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']
Vachel answered 2/2, 2019 at 20:14 Comment(3)
did you install pandas?Turbojet
Please clean up your output to show only the parts relevant for your problem. It is very likely you did not install pandas. I'm guessing you are perhaps using a virtual environment called 'base'? You need to install all necessary packages within that environment.Cryptocrystalline
Does this answer your question? Unable to import a module that is definitely installedWhiffet
C
6

You need to install pandas with:

pip install pandas

If you run into issues with privileges, you may need to run:

sudo pip install pandas

It is also possible on Python 3 that you may need to run:

pip3 install pandas (although pip may be pointing to pip3 already). You can read about differences between pip versions on this SO post.

If you don't have pip installed, see here for installation.

Clive answered 2/2, 2019 at 21:4 Comment(2)
Hello PJW, I modified my post. I tried all your advice but it doesn't seem to work. I surfed across web with still no answers ....Vachel
Yeah it seems like the Pandas package is being installed in a different path than your Python installation. If you're doing everything inside your base virtual env, then it should work..... not sure.Clive
S
1

Check pandas package path from your env with:
jupyter kernelspec list

If you see the path: /Users/yourname/Library/Jupyter/kernels/yourenv

Delete that Jupyter folder from Library and run again.

Semidiurnal answered 5/3, 2019 at 21:36 Comment(0)
P
1

For me, the below command works in MAC

sudo -H pip3 install pandas --upgrade

Pleuropneumonia answered 8/2, 2023 at 15:46 Comment(0)
B
0

if you see such this in your IDE and the error "no module named pandas" when you run your code, it means that pandas has not been installed although you have done "pip install pandas" or whatever.

Go to file > settings > project interpreter and see if pandas is available in the list of packages. if not simply click + (plus), choose pandas and install it in your project environment .
see picture then wait for you IDE update your project skeletons ... voila , the error disappears !

Biparietal answered 22/8, 2019 at 7:21 Comment(0)
T
0

When entering the command to run your file, make sure you specify which version of python you're using. For example, instead of python filename.py, use python3 filename.py or python2 filename.py

Totter answered 11/9, 2019 at 20:25 Comment(0)
W
0

your pandas is installed in python3 (3.7):

Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.24.0)

but you are running python2.7 and pandas isn't in your path 2.7:

['/Users/thibaultmonsel/Desktop/ML_folder', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', 
'/Library/Python/2.7/site-packages', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

try to simply run your script using python3:

python3 help1.py

or add python3 header, example:

#!/usr/bin/env python3

or 

#!/usr/local/bin/python3

and if that doesn't work (like I had the same problem because I was importing pandas from jupyter notebook, macos), you can ultimately import from your --user path, example:

sys.path.append("/Users/<USER>/Library/Python/3.7/lib/python/site-packages")

but make sure you have pandas installed there (..python/site-packages/pandas) using

pip3 install pandas --user

Webb answered 3/1, 2020 at 18:16 Comment(0)
H
0

Check your virtual environment (you can see it at the left corner of VS code) and install the package (e.g. pandas) in your virtual environment like this:

conda install -n yourenvname [package]
Hanahanae answered 6/11, 2020 at 15:10 Comment(0)
H
0

install pandas outside the project, I wanted to download it only for an env environment but I got the same error so I did it from outside.

Homovec answered 1/3, 2021 at 16:56 Comment(0)
G
0
  • Code > Preferences > Settings
  • In Search, type "interpreter"
  • You will see a bar : Python: Default Interpreter Path
  • Paste your correct path to Python (something like "/usr/local/bin/python3" in Mac), it will automatically save
  • Then go back to your python file and try to run
Galilee answered 6/3, 2021 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.