PythonIDE · First-run guide

How to run Python on iPad and iPhone

Run your first .py file, then turn a small CSV into a chart in a Jupyter notebook. Both examples use PythonIDE’s on-device Python runtime, not a remote server.

Run a Python file

Open PythonIDE on your iPad or iPhone. This first example uses only Python itself, so you don’t need to install any packages or set up Jupyter.

  1. Create a script

    In a local workspace, create a Python file named hello.py and paste in these two lines.

    name = "PythonIDE"
    print(f"Hello from {name}!")
  2. Run it and check the output

    Open hello.py in the editor and tap the Run button (▶). The output should contain the line below. Change name and run the file again to see it change.

    Hello from PythonIDE!

Go from a CSV to a chart

Practice a common data workflow with fictional sales: load a CSV with pandas, remove a row with an invalid quantity, and plot revenue with Matplotlib.

  1. Put the notebook and CSV together

    Download sample-sales.csv and copy it into a local PythonIDE project folder. Create a notebook named sales-chart.ipynb in the same folder. Add three code cells and run them in order, one block per cell.

    If you already have the CSV locally, this walkthrough has no online data source.

  2. Cell 1: Load and inspect the CSV

    Read the file and print its first three rows. If the file is not found, the error shows the notebook’s working folder. Move or copy the file there, or update csv_file to point to it.

    from pathlib import Path
    
    import pandas as pd
    
    csv_file = Path("sample-sales.csv")
    if not csv_file.is_file():
        raise FileNotFoundError(f"Put the CSV in {Path.cwd()}")
    sales = pd.read_csv(csv_file)
    print(sales.head(3).to_string(index=False))
  3. Cell 2: Clean and group the rows

    Convert the quantity and price columns to numbers, drop rows that failed conversion, then calculate revenue per product. This preserves exact whole cents until the display step. The sample contains one invalid quantity, unknown; no values are guessed or filled in.

    columns = ["units", "unit_price_cents"]
    for column in columns:
        sales[column] = pd.to_numeric(
            sales[column], errors="coerce"
        )
    
    clean = sales.dropna(subset=columns).copy()
    print(f"Skipped {len(sales) - len(clean)} invalid row(s)")
    
    clean["revenue_cents"] = (
        clean["units"] * clean["unit_price_cents"]
    ).astype(int)
    
    summary = clean.groupby("product").agg(
        units=("units", "sum"),
        revenue_cents=("revenue_cents", "sum"),
    )
    summary["revenue_usd"] = summary["revenue_cents"] / 100
    summary = summary.sort_values("revenue_usd", ascending=False)
    for product, row in summary.iterrows():
        print(f"{product}: {row.units:.0f} units, "
              f"${row.revenue_usd:.2f}")
    Skipped 1 invalid row(s)
    Notebook: 4 units, $34.00
    Tea: 8 units, $24.00
    Pen: 6 units, $12.00
  4. Cell 3: Plot revenue

    The chart should show Notebook at $34, Tea at $24, and Pen at $12, in that order. Tea sells the most units, but Notebook earns the most revenue.

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots(figsize=(5, 3))
    ax.bar(summary.index, summary["revenue_usd"])
    ax.set_title("Revenue by product")
    ax.set_ylabel("Revenue (USD)")
    fig.tight_layout()
    plt.show()

What needs a connection?

Can I run Python and notebooks offline?

Yes. Once PythonIDE and your files are on the device, a local script like hello.py can run offline. This notebook also runs locally once the CSV, pandas, and Matplotlib are available. Neither example needs an online Jupyter server or a cloud AI service.

What should I check if an import fails?

If you see ModuleNotFoundError for pandas or Matplotlib, check that the library is available to PythonIDE before disconnecting. Install or download any needed supported packages while online. iOS package compatibility can differ from a desktop Python environment.

Which features still need the internet?

Downloading the app or packages, fetching online data, using cloud AI, or connecting to a remote server requires a network connection. Download iCloud-only files to the device before relying on them offline.

Ready to run your first script?