ImportError: No module named 'xlrd'

Viewed 134837

I am currently using PyCharm with Python version 3.4.3 for this particular project.

This PyCharm previously had Python2.7, and I upgraded to 3.4.3.

I am trying to fetch data from an Excel file using Pandas.

Here is my code:

import pandas as pd

df = pd.read_excel("File.xls", "Sheet1")
print (df)

When I ran this code, I am getting this error.

ImportError: No module named 'xlrd'

I searched Stackoverflow and found some suggestions: I tried with

pip install xlrd

But, when I did that, the message says

"Requirement already satisfied: xlrd in ./anaconda2/usr/lib/python2.7/site-packages"

Any suggestion?

14 Answers

You have to download xlrd library because pandas require it.

In Pycharm I downloaded it in File -> Settings -> Project: [PROJECT NAME] -> Project Interpreter enter image description here

Running the pip install xlrd completed the installation, but that did not resolve the "no named module named xlrd" error.

Copying the xlrd folder to the same folder where the .py programs are stored, resolved this issue.

The problem seems to be because of multiple python versions in the system, where requirement might be satisfied for one and not for the other.

In this case the requirement is satisfied for python2 but not for python3, you need to specify that the download needs to be for python3.

In reference to the answers mentioned above, what worked for me is

python3 -m pip install xlrd

specifying python3 rather than pip3 worked for me.

For me the solution was uninstalling xlrd using pip uninstall xlrd, and then installing it again using pip install xlrd.

The answers listed to date did not work for me. Sadly, the only thing I had to do after running pip install xlrd, was to restart Visual Studio Code on my Windows 10. I know that it is a different OS than the OP, but hopefully, that helps someone else.

Oh yeah, and I know... restarting should have been my first step.

The same happened to me using pycharm, I had installed it with pip, pip3 and anaconda and it still didn't work. I manually installed the package from pycharm-> preferences -> project -> project interpreter -> + and it worked.

If you are using a virtual environment use "pipenv install xlrd" instead of "pip install xlrd". That should work.

If you are facing issues in Windows then try the steps below which works for me:

  1. go to the location %localappdata%
    • C:\Users\<YourSystem>\AppData\Local\Programs\Python\Python38-32\Scripts
  2. Open cmd ternimal at this location
  3. run pip install xlrd

I copy the modules xlrd and xlrd-1.2.0.dist-info to the project file after pip/conda install xlrd , and it worked.

I was using VS Code and in my case I have already installed xlrd but the import was not detecting. There were two reason for it:

  1. I have not restarted my VS Code after pip install xlrd. So, just restart it.
  2. I have two versions of Python installed and my VS Code interpreter was pointing to a previous version of Python which was not there in enviornment variable path of windows. So, I just changed the interpreter which the VS code was pointing. There is an interpreter version shown on bottom right corner of VS code and we can change it from there.
Related