144

I am trying to read a .xlsx with pandas, but get the follwing error:

data = pd.read_excel(low_memory=False, io="DataAnalysis1/temp1.xlsx").fillna(value=0) 

Traceback (most recent call last):
  File "/Users/Vineeth/PycharmProjects/DataAnalysis1/try1.py", line 9, in <module>
    data = pd.read_excel(low_memory=False, io="DataAnalysis1/temp1.xlsx").fillna(value=0)
  File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/util/_decorators.py", line 118, in wrapper
    return func(*args, **kwargs)
  File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/io/excel.py", line 230, in read_excel
    io = ExcelFile(io, engine=engine)
  File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/io/excel.py", line 263, in __init__
    raise ImportError(err_msg)
ImportError: Install xlrd >= 0.9.0 for Excel support

I've also tried

data = pd.read_excel("DataAnalysis1/temp1.xlsx", low_memory=False).fillna(value=0)

And I Still get the same error.

Background: I'm trying to extract an excel file with multiple worksheets as a dict of data frames.I installed xlrd version 0.9.0 and the latest version(1.1.0) but I still get the same error. Thanks!

Grr
  • 15,553
  • 7
  • 65
  • 85
Vineeth Sai
  • 1,497
  • 2
  • 9
  • 10
  • 4
    Did you try listening to the error message and installing the `xlrd` package? – cs95 Jan 02 '18 at 19:13
  • 1
    Yes, I installed the `xlrd` package. Edit: I tried to import the package, but python gives me a `import xlrd ImportError: No module named xlrd` error – Vineeth Sai Jan 02 '18 at 19:18
  • 1
    I'm guessing you installed for a different python version. – cs95 Jan 02 '18 at 19:20
  • 1
    @cs95, just got same error message, point is why i got this error message when i am just using function of this library, why didn't pandas installed all its dependency library. itself :( – Achintya Ranjan Chaudhary Apr 11 '21 at 18:39

20 Answers20

156

As @COLDSPEED so eloquently pointed out the error explicitly tells you to install xlrd.

pip install xlrd

And you will be good to go.

Grr
  • 15,553
  • 7
  • 65
  • 85
  • 7
    I exactly had the same issue, I had to force re-install xlrd. pip install --upgrade --force-reinstall xlrd – Tamas Szuromi Feb 05 '18 at 13:17
  • 8
    @TamasSzuromi Unfortunately I keep having the same error message after trying both of your commands : `Install xlrd >= 0.9.0 for Excel support ` :/ – Revolucion for Monica May 14 '18 at 10:12
  • same here (on v 1.1.0)...and I cannot import it either, as suggested here https://stackoverflow.com/questions/51227745/importerror-install-xlrd-0-9-0-for-excel-support-when-using-pd-readexcel-to/51286813 – jjrr Nov 01 '18 at 15:39
  • 4
    tech-prism's answer below is more modern. – Parm May 19 '21 at 20:52
  • 1
    If you see this message: _Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl instead._ Please see message from @tech-prism and go for `pip install openpyxl` – Wojciech Jakubas Dec 13 '21 at 11:25
117

Since December 2020 xlrd no longer supports xlsx-Files as explained in the official changelog. You can use openpyxl instead:

pip install openpyxl

And in your python-file:

import pandas as pd
pd.read_excel('path/to/file.xlsx', engine='openpyxl')
tech-prism
  • 1,215
  • 1
  • 7
  • 8
  • 4
    That is the only answer that worked for me! Thanks! I hope they accept your answer. – Charles Santana Feb 15 '21 at 23:05
  • 1
    This is exactly what I needed. My program ran fine on Python 3.9 with a newer version of pandas (1.2.3) but trying to make it compatible with python 3.6 I can only get pandas up to 1.1.5 which must still use XLRD as the default engine. Thank you for this answer! – Drew Mares Apr 09 '21 at 16:06
  • For me in the terminal: pip install openpyxl command, solved the issue. No need to set: engine='openpyxl' in the read_excel method. But works with it , too. Just make sure its installed on your path. – tonycor nikolauos Aug 14 '22 at 20:15
38

Either use:

pip install xlrd

And if you are using conda, use

conda install -c anaconda xlrd

That's it. good luck.

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83
E. Erfan
  • 1,239
  • 19
  • 37
9

If you are in ubuntu this work for me:

python3 -m pip install openpyxl
python3 -m pip install xlrd
Gustavo Marquez
  • 419
  • 4
  • 6
7

This happened to me after I ran a script with cProfile a la python3 -m cProfile script.py even though xlrd was already installed and had never thrown this error before. it persisted even under python3 script.py. (Granted, I agree this wasn't what happened to OP, given the obvious import error)

However, for cases like mine, the following fixed the issue, despite being told "requirement already met" in every case.

pip install --upgrade pandas
pip install --upgrade xlrd

Pretty confounding stuff; not sure if cProfile was the cause or just a coincidence

The following should work, assuming your pip install operated on python2.

python3 -m pip install xlrd
3pitt
  • 899
  • 13
  • 21
6

I was getting an error

"ImportError: Install xlrd >= 1.0.0 for Excel support"

on Pycharm for below code

import pandas as pd
df2 = pd.read_excel("data.xlsx")
print(df2.head(3))
print(df2.tail(3))

Solution : pip install xlrd

It resolved error after using this. Also no need to use "import xlrd"

Omkar
  • 3,253
  • 3
  • 20
  • 36
3

This works for me: For Python 3

pip3 install xlrd --user

For Python2

pip install xlrd --user

Minhaj Javed
  • 913
  • 8
  • 20
2

I don't know if this will be helpful for someone, but I had the same problem. I wrote pip install xlrd in the anaconda prompt while in the specific environment and it said it was installed, but when I looked at the installed packages it wasn't there. What solved the problem was "moving" (I don't know the terminology for it) into the Scripts folder of the specific environment and do the pip install xlrd there. Hope this is useful for someone :D

NickD
  • 5,937
  • 1
  • 21
  • 38
2

Was getting the error while I was using jupyter.

ModuleNotFoundError: No module named 'xlrd'
...
ImportError: Install xlrd >= 0.9.0 for Excel support

it was resolved for me after using.

!pip install xlrd
Santosh sanwal
  • 134
  • 1
  • 4
  • 15
1

I encountered same problem and took 2 hours to figure it out.

  1. pip install xlrd (latest)
  2. pip install pandas (latest)
  3. Go to C:\Python27\Lib\site-packages and check for xlrd folder (if there are 2 of them) delete the old version
  4. open a new terminal and use pandas to read excel. It should work.
Alex Myers
  • 6,196
  • 7
  • 23
  • 39
Vivek Sh
  • 11
  • 1
1

I had the same problem and none of the above answers worked. If you go into the settings (CTRL + ALT + s) and search for project interpreter you will see all of the installed packages. Click the + button at the top right and search for xlrd, then click install package at the bottom left.

I had already done the "pip install xlrd" command from the file location of my python.exe before this, so you may need to do that as well. (you can find the file location by searching it in windows search bar and right click -> open file location, then type cmd into the file explorer address bar)

Joe Giusti
  • 159
  • 1
  • 3
1

This can be because your required libraries are been installed in Python environment instead of Spyder.

https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder

Babulal
  • 349
  • 3
  • 11
1

I had the same problem. Actually, the problem is that even after installing packages/libraries using pip these packages are not integrated with IDE. So, need to add libraries specifically to the ide.

0

First of all you need to install xlrd & pandas packages. Then try below code.

import xlrd
import pandas as pd

xl = pd.ExcelFile("fileName.xlsx")
print(xl.parse(xl.sheet_names[0]))
reza.cse08
  • 5,938
  • 48
  • 39
0

You need to install the "xlrd" lib

For Linux (Ubuntu and Derivates):

Installing via pip: python -m pip install --user xlrd

Install system-wide via a Linux package manager: *sudo apt-get install python-xlrd

Windows:

Installing via pip: *pip install xlrd

Download the files: https://pypi.org/project/xlrd/

nilsoviani
  • 344
  • 5
  • 16
0

Another possibility, is the machine has an older version of xlrd installed separately, and it's not in the "..:\Python27\Scripts.." folder.

In another word, there are 2 different versions of xlrd in the machine.

enter image description here

when you check the version below, it reads the one not in the "..:\Python27\Scripts.." folder, no matter how updated you done with pip.

print xlrd.__version__

Delete the whole redundant sub-folder, and it works. (in addition to xlrd, I had another library encountered the same)

Mark K
  • 8,767
  • 14
  • 58
  • 118
0

I encountered a similar issue trying to use xlrd in jupyter notebook. I notice you are using a virtual environment and that was the key to my issue as well. I had xlrd installed in my venv, but I had not properly installed a kernel for that virtual environment in my notebook.

To get it to work, I created my virtual environment and activated it.

Then... pip install ipykernel

And then... ipython kernel install --user --name=myproject

Finally, start jupyter notebooks and when you create a new notebook, select the name you created (in this example, 'myproject')

Hope that helps.

placeybordeaux
  • 2,138
  • 1
  • 20
  • 42
0

Please make sure your python or python3 can see xlrd installation. I had a situation where python3.5 and python3.7 were installed in two different locations. While xlrd was installed with python3.5, I was using python3 (from python3.7 dir) to run my script and got the same error reported above. When I used the correct python (viz. python3.5 dir) to run my script, I was able to read the excel spread sheet without a problem.

C K
  • 1
0

As @WojciechJakubas mentioned to install openpyxl instead of xlrd, I used openpyxl and it worked.

pip install openpyxl

import openpyxl
path = "path to file.xlxs"
wb_obj = openpyxl.load_workbook(path)
sheet_obj = wb_obj.active
length_col = sheet_obj.max_row
print("Length of rows : ", length_col)

I hope it will help lot of people in 2023.

Sarmad Ali
  • 122
  • 1
  • 13
0

Nothing worked for me until I just uninstalled it first and reinstalled from scratch:

pip uninstall xlrd
pip install xlrd
Boingoloid
  • 107
  • 2
  • 9