Pandas ExcelWriter .save();权限错误[WinError 32]

时间:2018-05-23 07:17:09

标签: python excel python-3.x pandas pandas.excelwriter

我尝试使用ExcelWriter写出文档并遇到以下问题:

当我运行我的程序时,有时会发出如下警告:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\...\AppData\\Local\\Temp\\tmpk6915sp2'

据说该错误来自ExcelWriter .save()方法。

我尝试使用ExcelWriter的.close()方法,但有时问题仍然存在。我的意思有时候是,如果我多次重新运行程序,那么程序就像没有错误一样运行。

我不明白的是,它为什么/有时/仍然存在,我该如何解决?

我遇到了几个有相同错误但仍与ExcelWriter无关的线程,我希望有人可以帮助我。提前谢谢!

1 个答案:

答案 0 :(得分:0)

是的,我的最新应用程序(在Windows中开发)也遇到了类似的问题。就我而言,如果发生异常,我必须重新运行一次,直到获得成功。因此,我按照以下代码段暂时绕过了这种情况。

  for count in range(1, 11):
    try:
        print('[+] Running - {}'.format(count))
        # report creation function goes here
        print('[+] Success excel file created.')
        break
    except Exception as error:
        print('[-] Exceptional error - {}'.format(error))
        print('[-] Re-running - {}'.format(count))
        continue