简体   繁体   English

如何为Mac OS X创建安装程序

[英]How to create installer for mac osx

I am making an app in python, which is able to open different file types. 我正在用python开发一个应用程序,它能够打开不同的文件类型。 This code in running fine on eclipse while passing filename which I want to open and configuration file as arguments respectively. 这段代码在eclipse上运行良好,同时分别传递了我想打开的文件名和配置文件作为参数。 Now I converted this into application by using py2app. 现在,我使用py2app将其转换为应用程序。 So, the issue is how to deal with arguments, as different file types need to be open through app and this app also needs configuration file while processing. 因此,问题在于如何处理参数,因为需要通过应用打开不同的文件类型,并且此应用在处理时还需要配置文件。 Is there any different methods available for making app which can be installed on mac osx. 是否有任何其他方法可用于制作可安装在Mac OS X上的应用程序。

Have you had a look at py2app ? 您看过py2app吗? Its pretty much py2exe for Mac OSX and creates a standalone app. 它几乎适用于Mac OSX的py2exe,并创建了一个独立的应用程序。 You can handle the logger and configuration files pretty easily and keep your app nice and simple to distribute. 您可以非常轻松地处理记录器和配置文件,并使应用程序美观且易于分发。

I usually store logger files in the users home directory as a hidden file - a lot of Mac OSX applications do this - i'm not sure if its officially the way to go but it works. 我通常将记录器文件作为隐藏文件存储在用户的主目录中-许多Mac OSX应用程序都执行此操作-我不确定它是否正式可用,但是否可行。 The home directory is guaranteed to exist and you won't get permission errors like you would when you write to other random folders or to location inside the app bundle. 保证主目录存在,并且不会像写入其他随机文件夹或应用程序捆绑包内的位置那样出现权限错误。

You can do this and keep your code cross platform buy opening files like this 您可以这样做,并使您的代码跨平台购买,像这样打开文件

import platform
import os

if platform.system() == 'Darwin': # We're on a mac
        # Store the saved rates in the users home dir - note the dot at the start
        # of the filename to keep the file hidden
        home = os.path.expanduser("~")
        filename = os.path.join(home, '.myHiddenLogger')

else: # We're on another platform, create whatever filename you were using before
        filename = 'myLogger'

As for the configuration file, this answer here tells you how to bundle a resource file in with you're app. 至于配置文件,这里的答案告诉您如何将资源文件与您的应用程序捆绑在一起。 If you want to write stuff to this configuration file and save it for next time, you'll have to store it as a hidden file like the logger - this will stop the app from crashing due to permission errors when it tried to write to a file inside the app bundle. 如果您想将内容写入此配置文件并下次保存,则必须像记录程序一样将其存储为隐藏文件-这会阻止应用在尝试写入文件时由于权限错误而崩溃。应用包中的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM