Question

I'm a complete Python beginner and I wanted to know how to open an .xls file using Python 3.3 and xlrd 0.9.2 on mac OS X 10.9.1. I have searched long and hard to try and find an answer, but to no avail. Funky.xls is currently saved on my desktop. Unfortunately, xlrd doesn't seem to be able to find it.

Here is the error message. Thank you all for your help in advance.

Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.

>>> import xlrd
>>> book = xlrd.open_workbook("Funky.xls")

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    book = xlrd.open_workbook("Funky.xls")
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/xlrd/__init__.py", line 394, in open_workbook
    f = open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'Funky.xls'
>>> 
Was it helpful?

Solution

The last part of error message is saying that the file cannot be found:

FileNotFoundError: [Errno 2] No such file or directory: 'Funky.xls'

The most likely reason for that is that the xls file that you are trying to parse isn't in the same directory as the program that you are trying to parse it with.

To fix this you just need to specify the full path to the file. Something like this:

>>> import xlrd
>>> book = xlrd.open_workbook("/Users/username/Desktop/Funky.xls")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top