Basic steps to build and run an iOS project generated by pn.
pn run ios unpacks the bundled iOS template (Swift + PythonKit, with optional Rubicon-ObjC) into build/ios/ios_template and copies your app/ under build/ios/app/ for later integration steps. The template zip is bundled with the package, so no network is required to scaffold.
The default ViewController.swift initializes PythonKit, prints the Python version, and attempts to import rubicon.objc if present.
Your app/ directory contains @pn.component function components.
The native iOS template uses
[create_screen][pythonnative.create_screen] internally to bootstrap your
root component inside a ViewController. You don't call create_screen
directly; just export your component and configure the entry point in
pythonnative.json.
pn run iosOr prepare without building:
pn run ios --prepare-onlyYou can then open build/ios/ios_template/ios_template.xcodeproj in Xcode.
After building and installing into the Simulator, pn run ios launches the app
with xcrun simctl launch --console-pty, which attaches your terminal to the
app's stdout/stderr. Python print() calls and exception tracebacks appear
inline until you press Ctrl+C, at which point the app is terminated cleanly.
SIMCTL_CHILD_PYTHONUNBUFFERED=1 is forwarded to the launched process so
output is line-buffered and doesn't get stuck behind Python's stream buffers.
Pass --no-logs to skip the console attach and use the legacy
fire-and-exit launch instead. That's useful when you want to continue
interacting with the app from Xcode or Console.app, or when running in
a non-interactive context like CI (see the e2e.yml workflow for an
example).
- Xcode 14 or newer.
simctl launch --console-ptywas added in Xcode 14; on older toolchains either upgrade Xcode or pass--no-logs. - Python
print()output on the Simulator is routed through the app's stderr by thepythonnative._ios_logmodule. This runs automatically when the embedded Python bootstraps on iOS, so you don't need to configure it.
Remove the build directory safely:
pn clean- Building and running for Simulator via the CLI is best-effort. Opening the generated project in Xcode is recommended for iterative development.
See Troubleshooting for the most common errors and their fixes.
- Try the Android counterpart: Android guide.
- Build a real screen: Examples.
- Iterate faster with Hot reload.