1

I'm trying to read a .xlxs file in Python using xlrd, but I keep getting the error Unable to import xlrd.

When I try to re-install xlrd using:

pip install xlrd

I keep getting the message

Requirement already satisfied: xlrd in ./anaconda3/lib/python3.6/site-packages (1.1.0)

And my error message after running my code is

Traceback (most recent call last):
    File "/Users/YoungFreeesh/Venture Capital Internship/.../.../Read-csv.py", line 2, in <module>
       import xlrd # import the xlrd module
ImportError: No module named xlrd

Also, not sure if this is relevant but I'm using Visual Studio & Python 3.6.5

I'm not sure why I can't import xlrd since I already have it downloaded.

martineau
  • 99,260
  • 22
  • 139
  • 249
WhiteDillPickle
  • 115
  • 1
  • 3
  • 8
  • It likely has to do with your environment. Figure out where the actual python files for xlrd are located on your computer and try the following code at the top of your module: `import os; os.path.extend([r"path/to/xlrd/parent/folder"])` – ThePoetCoder Jun 06 '18 at 19:38
  • Do you mean like this? `import os` `os.path.extend([r"/Users/YoungFreeesh/anaconda3/lib/python3.6/site-packages/"])` `import xlrd # import the xlrd module` Because this still isn't working. The xlrd folder is in site-packages. – WhiteDillPickle Jun 06 '18 at 19:46
  • Sorry if this is a dumb question but I've only started using python as of yesterday – WhiteDillPickle Jun 06 '18 at 19:57
  • Goodness, I remembered the wrong module. It's supposed to be `import sys; sys.path.extend([path])`. Sorry about that. – ThePoetCoder Jun 06 '18 at 20:02
  • 1
    That Works! Thanks! – WhiteDillPickle Jun 06 '18 at 20:35
  • So just FYI, this means that when you install something with pip it is going to your site-packages (like it's supposed to) but your PATH is not set up to look in those site packages for the things you import. So unless you want to add that text to every file you write, I'd suggest looking into how to permanently add something to your PATH. Here's a start: https://stackoverflow.com/questions/6318156/adding-python-path-on-windows-7#6318188 – ThePoetCoder Jun 06 '18 at 21:12

1 Answers1

0

I ran into a similar issue. Make sure you're pip installing the right version (3.x or 2.x). If you're using Python 3, pip3 install xlrd will make sure it is installed and accessible when running Python3 code.

Jacob Stern
  • 1,535
  • 12
  • 29