Closed RandallWert closed 2 years ago
the compiled app does not produce any xlsx file.
That seems unlikely. If there was any issue that caused xlsxwriter to not be able to create a file then it would raise a warning or exception.
It is more probable that the file is being created but not in the directory that you think it is in. Applications like py2app often use their own sandbox directory.
You should double check where the file is created by putting a simple print()
in the code after you create the filename:
cwd = os.getcwd()
filename = cwd + "/" + str_year + str_month + str_day + str_hour + str_min + str_sec + ".xlsx"
print(filename)
Also, this StackOverflow question indicates that cwd()
in py2app doesn't give you the assumed current working directory and shows how to work around that: https://stackoverflow.com/questions/11642540/python-change-cwd-of-script-bundled-with-py2app
Thanks for your quick reply. I have checked my entire hard disk, and the xlsx file is not being created anywhere. I also tried the solution suggested in response to that StackOverflow question, and my results remained the same: running in the IDE works fine, running the compiled app produces no xlsx file.
I suspect that the problem resides in py2app rather than XlsxWriter, so I have posted an issue there, too. In the meantime, I am going to try to write a simple text file and see whether that works. My client is adept with Excel and Numbers and can import a csv if necessary and format it as they desire.
Did you try putting in the print statement to see the file location?
Yes, and I must thank you for pushing me again to do that. It showed that it was trying to write the xlsx to .app/Contents/MacOS (similar to what that StackOverflow answer mentioned). But the xlsx was not there, either -- just two Unix executables, one named python and one named like my app. Also, the solution suggested in the answer to that StackOverflow question did not correct the target filepath to the desired directory.
I FaceTime with my son, the software engineer, every Sunday evening at this time anyway, so he guided me through the process of setting a relative path to the user's Desktop and putting the xlsx there. And now it works!
Thank you again for your quick replies. I have learned that the cwd is not always what I think it is.
Thanks for the followup and I'm glad you found a solution. Closing.
Current behavior
I am using XlsxWriter (version 3.0.3) in my Python 3.9 program to create an xlsx file. This works perfectly as intended when I run my program from the IDE (IDLE). But when I compile my program with py2app, although the compilation seems to run without problems and the compiled app runs correctly otherwise, the compiled app does not produce any xlsx file.
Based on what I read at stackoverflow, I have already tried specifying the full filepath instead of just the filename, but the behavior remains the same.
Expected behavior
The compiled app should produce the desired xlsx file, just as it does before compilation when executed from the IDE.
Sample code to reproduce
Environment
Any other information
No response
OpenOffice and LibreOffice users