简体   繁体   中英

How to create a mac app from python files

I currently have a python application that runs perfectly from the CLI and when I run it from an IDE. I want to make it into an application that will launch in 1 click from any mac computer. (Like any desktop application). Ideally, I can send someone the file, they do a simple install, then the program works. I have tried using platypus (works great for 1 file programs) and other methods of bundling apps. But none of them seem to work as the program is kinda complex.

Program Requirements:

  • Python3

  • Python Libraries tkinter, socket, threading, PIL etc

  • ~8 individual python files (controlled by 1 main menu)

  • Lots of images

I would like to have an install process, where you click next a bunch of times and agree to things, but if this isn't possible I can live without it.

Any help is greatly appreciated!

Use PyInstaller to build your package. I do not think they have an actual installer, but you could build your own GUI installer by using some CMD commands and something like tkinter.

I have used py2app for this in the past ( https://py2app.readthedocs.io/en/latest/ )

This article does a good job of explaining how to use it ( https://www.metachris.com/2015/11/create-standalone-mac-os-x-applications-with-python-and-py2app/ )

Basically you install the library and create a setup.py file that looks something like this

from setuptools import setup

APP = ['Sandwich.py']
APP_NAME = "SuperSandwich"
DATA_FILES = []

OPTIONS = {
    'argv_emulation': True,
    'iconfile': 'app.icns',
    'plist': {
        'CFBundleName': APP_NAME,
        'CFBundleDisplayName': APP_NAME,
        'CFBundleGetInfoString': "Making Sandwiches",
        'CFBundleIdentifier': "com.metachris.osx.sandwich",
        'CFBundleVersion': "0.1.0",
        'CFBundleShortVersionString': "0.1.0",
        'NSHumanReadableCopyright': u"Copyright © 2015, Chris Hager, All Rights Reserved"
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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