openpyxl [Errno 13] permission denied when creating xlsx unless using debugger

Question:

I’m trying to write an excel file using openpyxl. I’m using PyCharm Community Edition 2021.2.3, with Python 3.8.10.

When doing so, I get an exception

Exception: [Errno 13] Permission denied

I should precise, the file is not already opened. When I’m running the same code with the debugger, the file is successfully written, no permission issues.
Anyone knows why it works with the debugger only? What can I do to make it work without it? I’m the admin of my machine so any lack of permission I can address. I just tried everything, nothing seems to cut it. I’m able to generate any other file extensions with the same code. For some reason just the xlsx causes issues.

I didn’t post a code sample because it’s definitely not the problem, but here goes:

wb = openpyxl.workbook.Workbook()
ws = wb.active
ws.title = 'Title'
ws.append(["TITLE"])
wb.save(filename=os.path.join(os.getcwd(), "Example.xlsx"))
wb.close()


  
Asked By: Soyding Mete

||

Answers:

In case anyone encounters the same issue, writing an xlsx by the python script (and not through PyCharm’s debugger) was forbidden by the IT rules of my company, something to do with the application not being registered as being allowed to do so.

Answered By: Soyding Mete
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.