Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'xlrd'

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?

like image 751
Java Avatar asked Jul 21 '17 18:07

Java


People also ask

What is xlrd module in Python?

xlrd is a library for reading data and formatting information from Excel files in the historical . xls format.


Video Answer


4 Answers

I had the same problem. I went to the terminal (Using Linux), and typed

sudo pip3 install xlrd

Then I imported xlrd in python and used the same code:

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

It worked for me!!

like image 65
aztec242 Avatar answered Oct 17 '22 12:10

aztec242


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

like image 9
Pedro Machado Avatar answered Oct 17 '22 11:10

Pedro Machado


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.

like image 8
Amal Raj Avatar answered Oct 17 '22 10:10

Amal Raj


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.

like image 7
Aklank Jain Avatar answered Oct 17 '22 11:10

Aklank Jain