Python 有时,当我想关闭Excel文件时,会出现一个权限错误:[WinError 32]。为什么?

Python 有时,当我想关闭Excel文件时,会出现一个权限错误:[WinError 32]。为什么?,python,xlsxwriter,Python,Xlsxwriter,有一些向量,我想计算它们之间的相似性。我想将相似性值保存在Excel文件(.xlsx)中。 我使用的软件包是xlsxwriter。 但有时调用“close()”函数时会发生错误(但不是每次都发生,这意味着有时程序可以正确执行) 这是我的密码: #create a new Excel and a new sheet sim_order_file = xlsxwriter.Workbook(pre_code + '_' + sim_method + '_' + data_type + '.xlsx'

有一些向量,我想计算它们之间的相似性。我想将相似性值保存在Excel文件(.xlsx)中。 我使用的软件包是xlsxwriter。 但有时调用“close()”函数时会发生错误(但不是每次都发生,这意味着有时程序可以正确执行)

这是我的密码:

#create a new Excel and a new sheet
sim_order_file = xlsxwriter.Workbook(pre_code + '_' + sim_method + '_' + data_type + '.xlsx')
sim_order_sheet = sim_order_file.add_worksheet()

#write data in the cell
for i in range (len(all_name_sorted)):
    sim_order_sheet.write(i, 0, all_name_sorted[i])

for i in range (len(similarity_value_sorted)):
    sim_order_sheet.write(i, 1, similarity_value_sorted[i])

#close file
sim_order_file.close()
下面是错误的描述:

File "D:\python source\predict_software_ND\program_maliang\get_sim_order_xlsx_SVD.py", line 133, in get_sim_order_xlsx_SVD
sim_order_file.close()


File "E:\anaconda\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 299, in close
self._store_workbook()


File "E:\anaconda\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 627, in _store_workbook
os.remove(os_filename)

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

如果有人知道如何解决问题?

您可能已经在MS Excel中打开了它。实际上,我没有打开MS Excel软件。不过还是要谢谢你您可能已经在MS Excel中打开了它。实际上我没有打开MS Excel软件。不过还是要谢谢你