Aller au contenu

How to Run Python on Your iPhone

Python in DevBox runs on the device. What you can install is decided entirely by the platform it was built for, so that is where this starts.

Platform

ItemValue
InterpreterPython 3.12
Architecturei386 (32-bit x86)
C librarymusl (ld-musl-i386.so.1)
Base systemAlpine Linux 3.23
CompilerNone. No gcc, make, or dev headers
Package managerpip, wheels only
Binariespython, python3, pip, pip3
Project path/root/<projectname>

No compiler means pip cannot fall back to building from source. A package installs if a matching wheel exists, and does not if one does not.

Wheel tags

Open any package on PyPI, click Download files, and read the filenames.

Tag in filenameInstallsWhy
py3-none-anyYesPure Python, fits every platform
musllinux_1_2_i686YesRight libc, right architecture
manylinux*_x86_64Noglibc, and 64-bit
manylinux*_i686NoRight architecture, wrong libc
macosx_* / win_amd64NoWrong operating system
Source only (.tar.gz)NoNothing to build it with

Two conditions have to hold at once for a C package: musl rather than glibc, and 32-bit rather than 64. Most publishers ship manylinux and x86_64, which is why numpy and pandas do not install. The hardware is not the reason.

Common packages

PackageVerdict
requests, httpx, urllib3Installs
flask, jinja2, werkzeug, clickInstalls
beautifulsoup4, pyyaml, rich, python-dotenvInstalls
numpy, pandas, scipyCheck the tags first, usually no
pillow, lxml, cryptographyCheck the tags first

Compiled modules already present

These shipped with the interpreter, so they need no wheel:

_ssl, _hashlib, _sqlite3, _ctypes, _decimal, _lzma, _bz2, zlib, _socket, _asyncio, _multiprocessing, _csv, _json, readline, unicodedata.

HTTPS, SQLite, compression and async all work out of the box. _ctypes is the quiet one: several pure Python libraries bind to system libraries through it instead of shipping C, so they install where you might expect them not to.

Vendoring, which the template does

Create a Python project, choose Template, press run. A Flask app serves on port 8080 with no pip and no network.

Line two of app.py:

import sys; sys.path.insert(0, "./site-packages")

The dependencies sit inside the project rather than the system.

Template containsDetail
Vendored packagesFlask 3.1.3, Werkzeug, Jinja2, Click, MarkupSafe, itsdangerous, blinker, dotenv
Routesdashboard, analytics, customers, orders, messages, reports
HTML templates14
Bind address0.0.0.0:8080, not loopback
StructureBlueprint, config module, registered error handlers

Copy the pattern into your own projects:

pip install --target site-packages requests

Add the same sys.path.insert line. The project now carries its libraries, survives a runtime reset, and runs on another device unchanged.

The bind address is deliberate. Loopback restricts the server to the device; 0.0.0.0 lets your laptop reach it once external network access is on in Settings.

devbox.json

Press run on a .py file and DevBox executes python main.py, output going to the log panel. For a server you want the project to know it hosts one.

{
  "main": "python app.py",
  "browserURL": "http://127.0.0.1:8080"
}
KeyEffect
mainCommand the run button executes
browserURLWhere the built-in preview opens
httpRootDocument root for the built-in server
splitViewTypeiPad only, what sits beside the editor

The file is read when the project loads, so close and reopen the project after editing it.

Reset Runtime Environment

ClearedKept
Python, Node, PHP runtimesProjects in root
Installed librariesFiles in home
Runtime cachesMariaDB data

A broken pip state costs a minute. A project with a vendored site-packages folder comes through untouched.

Offline reference

The Docs tab stores 49 pages of Python documentation on the device, next to 112 for PHP and 60 for Node.

Backgrounding

iOS suspends apps that leave the screen, and a running server stops answering with them. The screen saver setting keeps the display awake so the app keeps running. Worth enabling before a long install.