Overview of py2app typing stubs
mainpy2app. These stubs are not intended to be exhaustive; they are designed specifically to provide sufficient type checking for the py2app codebase itself.repository·main·Indexed 19 days ago
https://github.com/ronaldoussoren/py2appA tool for creating standalone macOS application bundles or plugin bundles from Python GUI applications, allowing distribution to users without Python installed. Supports macOS 10.9+, Python 3.7+, and x86_64/arm64 architectures. Features include configuration via pyproject.toml or a legacy setuptools interface, support for Dark Mode, and utilities for handling C extensions, Cython, and SSL certificate validation via truststore.
py2app. These stubs are not intended to be exhaustive; they are designed specifically to provide sufficient type checking for the py2app codebase itself.Use --argv-emulation to intercept file-open and url-open events, adding the target resources to sys.argv.
WARNING: Do not use this with GUI toolkits, as the emulator can cause conflicts. Most GUI toolkits have their own APIs for handling these events.
To inject specific values into sys.argv immediately after argv[0], use --argv-inject <values>. The values are split using shlex.split.
--emulate-shell-environment: Use this if your application needs to access environment variables typically set in a user's shell profile (e.g., .bash_profile). By default, applications launched via Finder do not inherit these variables.--use-pythonpath: Allows the PYTHONPATH environment variable to affect the interpreter's search path. Note that this is generally not useful for standalone bundles as PYTHONPATH is not included in the minimal shell environment used by the application launcher.--site-packages: Includes system and user site-packages in sys.path. This makes the bundle less standalone as it becomes dependent on packages installed on the user's system.py2app provides the RESOURCEPATH environment variable. This variable contains the filesystem path to the 'Resources' folder located inside the application bundle. Use this variable to locate assets, data files, or other resources packaged with your app.Alias mode (-A or --alias) is designed for rapid development. Instead of creating a standalone, portable application, it builds an application bundle that uses your source and data files in-place.
Key benefits:
setuptools develop mode or Xcode's zero-link feature.Limitations:
To use alias mode, run setup.py with the py2app command and the -A flag. The application bundle will be located in the dist/ folder.
$ python setup.py py2app -ARecipes are a mechanism in py2app used to work around package incompatibilities and automatically strip unwanted dependencies. They are necessary for packages that:
__import__ or other methods to import code without using the standard import statement.Currently, py2app searches for recipes only within the py2app.recipes module.
To convert a Python script into a macOS application, you must first create a setup.py file. This file acts as the project configuration for setuptools. You can generate this file automatically using the py2applet command. If your application requires specific icon files (.icns) or additional data files, include them as arguments to the py2applet command.
$ py2applet --make-setup MyApplication.pyTo install or upgrade py2app, use pip with the -m flag to ensure it is installed for your specific Python interpreter. It is recommended to use the -U flag to ensure you have the latest version.
$ python3 -mpip install -U py2appTo build a simple py2app application, create a setup.py file that uses setuptools.setup with the app parameter pointing to your main script and setup_requires set to ['py2app']. Run the build using python setup.py py2app.
"""
py2app build script for MyApplication
Usage:
python setup.py py2app
"""
from setuptools import setup
setup(
app=["MyApplication.py"],
setup_requires=["py2app"],
)Note: Using the setuptools.setup() command interface is deprecated as of version 2.0. However, it is still supported for legacy configurations.
To use this method, create a setup.py script that calls setuptools.setup() with app or plugin arguments and a py2app configuration dictionary inside the options argument.
from setuptools import setup
setup(
app=...
options={
"py2app": {
...
}
}
)The preferred way to use py2app is as a command-line tool. It reads configuration from a pyproject.toml file in the current directory and performs the build process.
To run the build, use the following command:
$ python3 -m py2appOnce development is complete, you can build a standalone, redistributable version of your application.
Steps:
rm -rf build dist.py2app command without the alias flag: python setup.py py2app.dist/MyApplication.app.Note: Unlike alias mode, any changes to source code, data files, or options require you to run the py2app command again to rebuild the bundle.
To package the final application for distribution, you can right-click the .app bundle in Finder and select "Create Archive".
$ python setup.py py2app