我在Ubuntu上使用Python 2.7.11。Python:'NoneType'对象没有属性'decompressobj'
我试图用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.py
和TileList.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)
请发表您的实际代码 –