Crash when writing to a txt file from within a --onefile .app ?

309 views
Skip to first unread message

Ed May

unread,
Mar 14, 2022, 12:56:52 PM3/14/22
to PyInstaller
Hi everyone,

I am new to PyInstaller and having some trouble with one area? I was hoping that someone might know the right place to look for the method to use?

Using a very simple PyQt6 GUI - I have code that outputs a small text file when the user pressed a button. This uses the normal `with open("filename.txt", "w") as f:` python pattern. When I run the app using my normal python interpreter, it all works as expected: I get a small window and when you click the button, a txt file is created in the same folder as the script.

Screen Shot 2022-03-12 at 7.11.27 PM.png
Screen Shot 2022-03-12 at 7.11.36 PM.png

Screen Shot 2022-03-12 at 7.11.47 PM.png

so that is all fine.

I am able to run PyInstaller just fine, and the build all seems to go normal. I get a good .app file when it is done.
Screen Shot 2022-03-12 at 7.13.22 PM.png

I can then run the .app file just fine, and it opens with the same GUI as before the build.

BUT: as soon as I click the button in the GUI, the app crashes and I get an error report.
Screen Shot 2022-03-12 at 7.14.40 PM.png
Screen Shot 2022-03-12 at 7.22.44 PM.png


I am not sure where I'm going wrong there, or if I should be:
a) Using a different method than the with open(...)... syntax when using PyInstaller?
b) Is there something I should be setting in the .spec file perhaps?

# Environment / Versions:
  • Macbook 2021, Apple M1 Max
  • OS 12.2 (Monterey)
  • Python 3.10
  • PyInstaller 4.10
  • PyQt6
Any suggestions are much appreciated!
thanks very much,
-Ed

Steve Barnes

unread,
Mar 15, 2022, 3:21:58 AM3/15/22
to pyins...@googlegroups.com

Hi Ed,

 

I suspect that the problem is that you are not explicitly setting the path to write your text file into - if you are using onefile mode then the current working directory is either inside a zip file or a temporary location that you may not have write permissions for.

 

This is given away by: which is not a valid file path.

 

I would try one or more of:

 

  1. A fixed known path - easy but not portable,
  2. A path based on the user profile more portable,
  3. Prompting for an output path - probably what you eventually want.

 

Hope that helps.

 

Steve Barnes

 

From: pyins...@googlegroups.com <pyins...@googlegroups.com> On Behalf Of Ed May
Sent: 13 March 2022 00:23
To: PyInstaller <pyins...@googlegroups.com>
Subject: [PyInstaller] Crash when writing to a txt file from within a --onefile .app ?

 

Hi everyone,

 

I am new to PyInstaller and having some trouble with one area? I was hoping that someone might know the right place to look for the method to use?

 

Using a very simple PyQt6 GUI - I have code that outputs a small text file when the user pressed a button. This uses the normal `with open("filename.txt", "w") as f:` python pattern. When I run the app using my normal python interpreter, it all works as expected: I get a small window and when you click the button, a txt file is created in the same folder as the script.

 

 

 

so that is all fine.

 

I am able to run PyInstaller just fine, and the build all seems to go normal. I get a good .app file when it is done.

 

I can then run the .app file just fine, and it opens with the same GUI as before the build.

 

BUT: as soon as I click the button in the GUI, the app crashes and I get an error report.

 

 

I am not sure where I'm going wrong there, or if I should be:

a) Using a different method than the with open(...)... syntax when using PyInstaller?

b) Is there something I should be setting in the .spec file perhaps?

 

# Environment / Versions:

  • Macbook 2021, Apple M1 Max
  • OS 12.2 (Monterey)
  • Python 3.10
  • PyInstaller 4.10
  • PyQt6

Any suggestions are much appreciated!

thanks very much,

-Ed

 

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/16d1a387-27e1-4f2e-b69b-38c16fdfd3f2n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages