2

Please bear with me for seriously newbie (lack of) knowledge. I've trawled though previous answers on SO and made some progress, but I'm now really stuck and would really appreciate some help.

I have a working python (pygame) programme which includes images and sounds saved to the same folder as the .py file. I'm trying to turn it into an app with py2app.

I've written the setup.py file, and it seems to work fine. When I try to run the app it creates within the '/build/' directory, I just get an error in a popup window which reads '[appname] Error'. When I open the console, the relevant error message seems to be:

" 30/03/2013 08:47:02.425 com.apple.launchd.peruser.501[192]: ([0x0-0x1de2de1].org.pythonmac.unspecified.CookieMemory[17113]) Exited with code: 255"

I think my problem may be that the app is not able to access the data files (images, sounds) properly. I can see them there within the "Contents/Resources" folder. In order to get the image and sound files included within the app as Resources, I created a new folder (called "Memory") for them (within the /Users) directory - i.e. the same directory as where the setup.py and my .py program are. And I included a couple of lines of code at the start of the .py program to tell it to look in there for the image and sound files… since the .py program originally loaded them directly from the same folder in which it was saved. The .py program is happy with that change - when I run it directly via IDLE or the Terminal - but the app is not...

Here's my setup.py file:

 from setuptools import setup

    APP = ['CookieMemory.py']
    DATA_FILES = ['Memory']
    OPTIONS = {'iconfile':'cookieIcon.icns','argv_emulation': True}

    setup(
        app=APP,
        data_files=DATA_FILES,
        options={'py2app': OPTIONS},
        setup_requires=['py2app'],
    )

Here is the addition I made to the .py file:

import os,sys
currentFilePath=sys.argv[0]
currentDir=os.path.dirname(currentFilePath)
os.chdir(os.path.join(currentDir,"Memory"))

Any suggestions please?

4

1 回答 1

1

首先(并且与您的问题完全无关):不要使用 argv_emulation 除非您确实需要该功能(也就是说,您希望能够将文件放在应用程序上并让它们显示在 sys.argv 中), argv 模拟器是一个黑客和缓慢的应用程序启动。

当您从终端启动应用程序时会发生什么,例如:

$ dist/CookieMemory/Contents/MacOS/CookieMemory

这将在终端窗口中显示应用程序的标准错误/标准输出,如果运气好的话,应该会告诉你发生了什么。

于 2013-03-31T13:31:01.490 回答