Python:'NoneType'对象没有属性'decompressobj'

我在Ubuntu上使用Python 2.7.11。

我试图用xlrd包在Python中打开一个Excel文件(.xlsx)。 但是,当我尝试使用包中的open_workbook()函数打开我的Excel文件时,出现以下错误:

 Traceback (most recent call last): File "TileInserter.py", line 15, in <module> book = open_workbook(sheetPath, on_demand=True) File "/usr/local/lib/python2.7/site-packages/xlrd/__init__.py", line 422, in open_workbook ragged_rows=ragged_rows, File "/usr/local/lib/python2.7/site-packages/xlrd/xlsx.py", line 761, in open_workbook_2007_xml zflo = zf.open(component_names['xl/_rels/workbook.xml.rels']) File "/usr/local/lib/python2.7/zipfile.py", line 1010, in open close_fileobj=should_close) File "/usr/local/lib/python2.7/zipfile.py", line 526, in __init__ self._decompressor = zlib.decompressobj(-15) AttributeError: 'NoneType' object has no attribute 'decompressobj' 

我试图谷歌这个错误的原因,发现这可能会发生如果zlib库没有安装。 但是,当我使用PHP的phpinfo()函数检查,它显示zlib安装。 这也是最新的版本(版本1.2.8)。

所以我有点卡住了。 有谁知道如何解决这个问题?

编辑 :我在TileInserter.py实际代码是这样的( TileInserter.pyTileList.xlsx是在同一目录中):

 from xlrd import open_workbook sheetPath = "TileList.xlsx" #some more variables #Open Excel file book = open_workbook(sheetPath, on_demand=True) for name in book.sheet_names(): if name.endswith('1'): sheet = book.sheet_by_name(name) 

我在http://www.python-excel.org/上看到有一个build议用于处&#x7406;.xlsx文件的库openpyxl 。 这可能是你需要的而不是xlrd