openpyxl写入大文件内存问题 [英] openpyxl writing large file memory issue
本文介绍了openpyxl写入大文件内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用openpyxl只写工作簿创建一个75col x 650k行的文档,据说它的内存占用量接近恒定,但是过一会儿我在活动监视器中获得了17.2GB的内存使用量,这是我的代码我在使用,我在做错什么吗?
I'm trying to create a 75col by 650k rows document using openpyxl write only workbook, which is said to bear near constant memory footprint, but after a while I get 17.2GB memory usage in activity monitor, here's the code I'm using, am I doing something wrong?
def testOPENPYXL():
wb = openpyxl.Workbook(write_only=True)
ws = wb.create_sheet()
for irow in range(650000):
ws.append(['%d' % i for i in range(75)])
path = os.path.expanduser("~/Desktop/test/test.xlsx")
wb.save(path)
推荐答案
简单的解决方案是安装lxml
,我们在openpyxl中安装了一个垫片,该垫片模仿了lxml的流编写器,但内存效率不高.
The simple solution is to install lxml
we have a shim in openpyxl that mimics lxml's streaming writer but it isn't as memory efficient.
这篇关于openpyxl写入大文件内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文