I do have the same problem when I start the .py file via a double click (on a Windows 11 system).
The suggested reasons do not apply: The file I tried to write did not exist. Hence at was not open anywhere else. And yes, I do have write permission in the corresponding folder. Double click calls python3 to start the code in the .py file.
I noticed the following:
The problem is gone when I start the code in the command line of a terminal like so: python3 xyz.py
The problem is also gone when I create a batch file (.bat) that contains the line 'python3 xyz.py'.
Hence, my workaround is to create such a batch file so that I can start this batch file with a double click.
Problem solved for me. But it would be nice to know why a code that is started with a double click behaves that way.
writer = pd.ExcelWriter('pandas_simple.xlsx')
? Try it with just df.to_excel(sheet_name='Sheet1') and drop at thewriter
extras. – Cessation