New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data files aren't copied correctly with pathlib, or is it preferred to use some other path type? #437
Comments
I didn't want to put this in one big post, but for reference, here is the code for a working program:
this is what is in ./resources/json/data.json:
this is what is in ./resources/textfiles/textfile 1.txt:
this is what is in ./resources/textfiles/textfile 2.txt:
and it should open a window with something like this: |
One last thing: I've messed around with some of the parameters in the real program I'm working on and I can't remember what it was exactly, but I managed to get it to run in terminal using --no-chdir, so I think it was actually using my relative paths, but then it wouldn't run from the finder, probably because of #263. Anyways, the main thing I want to know is whether this is a bug or whether there is a single best way of doing this, because a lot of the description in the documentation and all has been pretty sparse |
I don't think this is related to pathlib, especially when it works with "--no-chdir". Have to checked if the resource files are actually copied in the app bundle at the location you expect them to be? |
I had to do some minor adjustments to from setuptools import setup
APP = ['main.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files = ['resources'],
options={'py2app': OPTIONS},
setup_requires=['py2app'],
) By just including the entire 'resources' folder in the app it works. I got a build error with your initial version due an error while trying to copy. That seems to be a bug in py2app itself that I haven't debugged yet. BTW. I used the py2app version from the repo, which has some code cleanup and modernisation compared to the last release. Those may have broken this. |
Sorry about the error there -- thought I posted the fixed version, but I'm glad you caught it. I tried pointing this like yours (at just ['resources']) and it works in the minimal working example but not in the real app. In that one, the 'resources' folder is ending up in main.app/Contents/Resources/ For what Unfortunately, I realize now there's a slightly different error in the actual app, which I wish I posted earlier above:
In the minimum working example I posted above I thought it'd be the same error, but it's not for some reason, and I'm not sure why the real app is zipping where the minimal one is not. In the real app, the data files are being put in at maingui.app/Contents/Resources/lib/python3.10/ (so there's maingui.app/Contents/Resources/lib/python3.10/[resources folder with data files found here] but if you unzip the folder, it's not in maingui.app/Contents/Resources/lib/python310/, which is where it's looking for it. |
I have a program (using a tkinter GUI) that has some data stored in .txt and .json files that are stored in a "resources" folder like this:
The way the files are accessed is with pathlib relative to
__file__
:Here's the way the data files are included in the setup.py:
The .app I get won't run in finder (gives the "launch error" pop-up). It does the same thing when I run it from the terminal (
open main.app
and doesn't put anything in the console. When I run it fromopen dist/main.app/Contents/MacOS/main
I get this in the console:I see that there might be some issues with pathlib (#436, #418), especially when using
__file__
. Could that be the problem here?The text was updated successfully, but these errors were encountered: