Search code examples
pythonmacosinstallationpy2app

python application to osx (mac) application


I have created Python app for mac OS. I am thinking to use py2app to convert it to the Mac OS application. I am new to Mac OS so I am not aware of all the concept and file structure of Mac OS but I am reading about it.

My program has two sub-applications,

sub-application 1: This will customize xml and put xml in the launchd's plist directory. I want to run my python program to run whenever macbook starts or someone logins that is why I am putting created xml file into launchd's plist. This sub-application should be run once only whenever installer is executed. (please provide the suggestions or any other way to perform this task).

sub-application 2: This will be my main program.

I have following questions,

  • How can I create an installer for my Python application so that I can pass installer to my friends and they can run the application?
    • I am reading about py2app, but is it most common?
    • Is it possible to run sub-application 1 and that will create macos application of sub-application 2 and provide the path where sub-application 2 is installed to sub application 1?
  • How can I make sub-application 1 to run only once when installer will be executed?
  • Do I need to include the default libraries(like os, sys, libcurl, etc) of the python in the installer package? If yes, how can I do it?
  • If my friend's PC does not have python or any inbuilt library for python and if he/she tries to run my installer what will happen, how can I prevent this scenario?

Thanks.


Solution

    1. You can use pyinstaller instead of py2app which I feel is a better option considering the control and features it gives. Build with the option --windowed on mac. This give you an (.app) file along with the unix executable version in dist folder.

    .app file is basically in a mac app structure (folder structure)

    check this official website with good starting examples

    1. For you case, sub application1 - you can write a shell script and invoke when the app is being added as Application in macOS.

    2. subapplication2 - will be your main program and will run whenever the application is invoked

    3. you don't have to include curl and os modules.If these are imported in your .py files, pyinstaller will automatically package them for you.

    4. your friends need not have python installed, pyinstaller will package python interpreter as well.

    For your second question - probably write a shell script to do that.