ImportError: No module named 'xlrd'

126,876

Solution 1

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!!

Solution 2

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

Solution 3

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.

Solution 4

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.

Solution 5

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

Share:
126,876

Related videos on Youtube

Java
Author by

Java

Updated on January 20, 2022

Comments

  • Java
    Java over 2 years

    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?

    • jonrsharpe
      jonrsharpe almost 7 years
      pip3 install xlrd? PyCharm will already be offering to install it through the context sensitive help if you've selected the correct interpreter for the project.
    • Joe
      Joe almost 7 years
      I agree with jon you are probably pointing at the wrong interpreter when running pip. If you go to you pycharm settings - project interpreter you will see exactly where pycharm is executing.
    • Mr_U4913
      Mr_U4913 almost 7 years
      open your anaconda prompt : conda install xlrd
    • jacoblaw
      jacoblaw almost 7 years
      what pip outputs clearly states you have it for python 2.7, and are trying to install for 2.7, but you are using 3.4.3 in pycharm.
    • Java
      Java almost 7 years
      I tried all above (pip3 install xlrd -> it says "The program 'pip3' is currently not installed. You can install it by typing: sudo apt-get install python3-pip, so I did. I went thru the process, and message said "python3-pip is already the newest version." I checked the interpreter, and it is pointing to 3.4.3 in PyCharm. I typed conda install xlrd. It went thru the process. It says "All requested packages already installed. But it says xlrd 1.0.0 py27_0.
    • voidpro
      voidpro almost 7 years
      One way is, copy the packege xlrd from ./anaconda2/usr/lib/python2.7/site-packages to the lib directory PyCharm installation directory. This is because pip installs the packeges to anaconda2 by default.
    • Mohamed A M-Hassan
      Mohamed A M-Hassan about 6 years
      thanks @KingJava I have same problem and I used "pip install xlrd" and it worked with me
    • WhitneyChia
      WhitneyChia about 4 years
      Shouldn't this be a transitive dependency for pandas and install when pandas is installed? I hit the same problem but this should've downloaded on its own right?
  • David Culbreth
    David Culbreth over 5 years
    I would caution that this method may not necessarily work for newer versions of Python, as 2.7 is not completely compatible with 3.x
  • Steven C. Howell
    Steven C. Howell over 5 years
    You are correct that you need to install xlrd. Rather than moving/copying the folder, try importing xlrd (import xlrd) before reading your Excel file.
  • Amal Raj
    Amal Raj over 5 years
    Yes...I did inport xlrd before trying to open the Excel file. But i kept getting the error...till i copied the folder
  • Adam Wheeler
    Adam Wheeler over 4 years
    It's not advisable to run pip with sudo (stackoverflow.com/questions/15028648/…)
  • D.L
    D.L almost 4 years
    I ran into the same issue (windows10). tried pip install, pip3 install and conda install. All failed. Moved the XLRD folder ('pip show XLRD') to the .py files folder and it works. Its not a great solution, but the only thing that worked.