|
|
1 săptămână în urmă | |
|---|---|---|
| .. | ||
| __pycache__ | 1 săptămână în urmă | |
| assets | 1 săptămână în urmă | |
| .gitignore | 1 săptămână în urmă | |
| Readme.md | 1 săptămână în urmă | |
| bundle_macos_demo.py | 1 săptămână în urmă | |
| bundle_macos_demo.spec | 1 săptămână în urmă | |
This example shows how to package a Python application for macOS with pyinstaller.
pip install pyinstaller
pyinstaller bundle_macos_demo.spec
The app is then located in the dist folder.
The function below will change the assets folder if we detect that we are inside a macOS bundle.
def set_assets_folder_if_macos_bundle():
import os
this_dir = str(os.path.dirname(os.path.realpath(__file__)))
if this_dir.endswith("Contents/Frameworks"):
assets_folder = this_dir + "/../Resources/assets"
hello_imgui.set_assets_folder(assets_folder)
print(f"Changed assets folder to: {assets_folder}")
The spec file contains the following lines that define the app name, icon and bundle identifier, as well as the assets folder to embed.
a = Analysis(
['bundle_macos_demo.py'],
...
datas=[("assets", "assets")], # Embed assets
...
)
...
...
app = BUNDLE(
coll,
name='bundle_macos_demo.app', # define app name
icon="logo_imgui_bundle.icns", # define app icon
bundle_identifier="bundle_macos_demo", # define bundle identifier
)