Reputation: 100
I'm using the last python version to date (3.13.1). I can compile code with xlwt, and executing my code though the console works. But when I want to execute the file double-click style it fails to create the xls file. It also fails when I export it as an .exe
Researching this issue, it seems it might not be xlwt fault since many people had the same problem with different python-to-excel libraries. I wonder if the issue is the python version itself (or a mix of both)
Does anyone know a reliable python3 version for writing on xls/xlsx and compiling to .exe? Or a recommended python-to-excel library since xlwt was archived in 2020?
Edit: It wasn't xlwt nor python, it was the SO. I'll leave the answer here so anyone with the same problem know how to solve it.
Upvotes: 0
Views: 42
Reputation: 100
It took me some time to understand what's going on because there are a lot of unanswered questions like this out there, and similar problems for different reasons.
I logged the error:
try:
wb.save(file)
except Exception as e:
# this way we can know about the type of error occurring
print("The error is: ",e)
time.sleep(30)
And find the issue.
#The error is: [Errno 13] Permission denied:
I didn't wanted to modify permissions for different reasons, so I opted for this solution:
#create folder if not exists
path = f'{tempfile.gettempdir()}' + "\\This_program\\"
file = path + f'{program_name}' + ".xls"
os.makedirs(os.path.dirname(file), exist_ok=True)
Then I can open the folder once I'm done:
wb.save(file)
subprocess.Popen(f'explorer {os.path.realpath(path)}')
I had to add this imports:
import tempfile
import subprocess
import os
And that's all! I hope the next person with this issue find this post. I now think it looks pretty obvious how to procede but at the moment was very confusing.
Upvotes: 0