Guides for Python Editor
How to run Python on iPhone and iPad (offline)
iOS doesn't come with Python, and you can't install it the way you would on a computer. Still, you can write and run real Python 3 code on an iPhone or iPad – on the train, in class or anywhere without Wi-Fi.
This guide shows you how that works, walks through a first script with input(), reads data from a file and draws a chart with numpy and matplotlib.
How Python runs on an iPhone
Apps can bring their own Python interpreter. When it runs on the device itself, your code never needs a server, and you don't need a connection to run it.
Python Editor works this way: Python 3 runs right in the app, also offline, without an account. print() and input() work in a console like a terminal, and errors come with their line number and a hint in plain words about what went wrong.
Your first script with input()
Interactive programs are the best way to start. This one asks for your name and a few scores and prints the average. Leave the input empty to finish.
name = input("Your name: ")
scores = []
while True:
entry = input("Score (leave empty to finish): ")
if entry == "":
break
scores.append(float(entry))
if scores:
average = sum(scores) / len(scores)
print(f"{name}, your average is {average:.1f}")
else:
print("No scores entered.")- input() always returns text, so float(entry) turns it into a number.
- The while True loop runs until break is reached.
- The f-string with :.1f prints one decimal place.
Reading files from your project
Real programs often work with data. Put a file called data.csv next to your script, with a header line name,points followed by one row per person, such as Ada,42. The csv module from the standard library reads it into dictionaries.
import csv
with open("data.csv", newline="") as f:
rows = list(csv.DictReader(f))
for row in rows:
print(row["name"], row["points"])
best = max(rows, key=lambda row: int(row["points"]))
print("Top score:", best["name"])- In Python Editor, every folder is a project with a file list and tabs.
- Your program reads files like data.csv from its own folder and can import your own modules.
- You can open folders from the Files app and iCloud Drive right where they are.
Which libraries are available
The whole standard library is there: math, random, csv, json, datetime, collections, re and the rest. Beyond that, Python Editor includes numpy and matplotlib, so you can calculate with arrays and draw charts offline. Other packages like pandas, scipy or sympy download the first time you import them – that one time you need an internet connection.
Not every package from PyPI works on a phone. Libraries that need a desktop window, access to hardware or a running server are usually not an option.
numpy and matplotlib on iPad
This script computes sine and cosine for 200 points and plots both curves. In Python Editor, the chart appears right in the console.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2 * np.pi, 200)
plt.plot(x, np.sin(x), label="sin(x)")
plt.plot(x, np.cos(x), label="cos(x)")
plt.legend()
plt.title("Sine and cosine")
plt.show()Understanding error messages
When something goes wrong, Python prints a traceback. Read it from the bottom: the last line names the error type and what happened, the lines above it show where. The ones you'll see most as a beginner:
| Error | Usually means |
|---|---|
| SyntaxError | A missing colon, bracket or quote |
| IndentationError | Lines inside a block aren't indented consistently |
| NameError | A typo in a name, or a variable used before it was set |
| ValueError | For example float("abc") – text that isn't a number |
| FileNotFoundError | The file isn't in the folder you think it is |
Tips for typing Python on a touch screen
Indentation is part of Python's syntax, which makes a good editor important on a phone. Python Editor indents automatically after a colon, closes brackets and quotes, and has a bar above the keyboard with Tab, symbols and building blocks like if, for, def and class. With a hardware keyboard on iPad, keyboard shortcuts work too.
Small projects to practice with
The fastest way to learn is to build small programs you actually want to use. Short sessions on the phone suit that well: write a few lines, run them, fix the next error. Python Editor comes with 20 examples to start from – among them guess the number, rock paper scissors, prime numbers and a quiz from JSON – and each one becomes a file of your own to change. A few more ideas:
- A tip calculator that asks for the bill and the number of people
- A vocabulary trainer that picks random words with the random module
- A countdown to your next holiday with the datetime module
- A small statistics script for your own CSV data
Frequently asked questions
Can I run Python on iPhone without internet?
Yes. Python Editor runs Python 3 on the device itself, including the standard library, numpy and matplotlib. Only extra packages like pandas need a connection once, when they download on first import.
Can I use pandas on iPad?
In Python Editor, pandas downloads the first time your program imports it. After that, you can use it like on a computer.
Does input() work on iPhone?
Yes. In Python Editor, input() asks for your answer in the console, just like in a terminal on a computer.