Skip to main content
Lectra runs Python on your iPad, so you can work through a problem set or analyze data next to your readings. Python comes with NumPy, pandas, Matplotlib, and Pillow. After a one-time download, it runs without an internet connection.

Before you begin

  • The first time you run Python, your iPad needs an internet connection. Lectra downloads Python once, about 70 MB. After that, Python works offline.
  • To install extra packages, you need an internet connection each time you install one.

Where you can run Python

There’s no Run button for .py files in the code editor. Run scripts from the project’s terminal. To learn more, see Use the terminal and Use the code editor.

The first run

The first time you run code, Lectra gets Python ready. A notebook shows the progress at the top:
  1. Downloading Python… with a percentage, the first time only.
  2. Starting Python…
  3. Python ready
If your iPad is offline during the first run, the cell shows “Python couldn’t start: it needs a one-time download to finish setting up, and the network isn’t reachable right now.” Connect to the internet, and then run the cell again.
If your iPad runs low on storage, iPadOS can remove the Python download to free up space. Lectra downloads it again the next time you run Python.

Included packages

Lectra includes Python 3.12 and these packages. You can import them without installing anything. Lectra also includes the packages these depend on, such as six, cycler, fonttools, kiwisolver, pyparsing, and packaging.

Install more packages

You can add packages from PyPI, the public Python package index, while your iPad is online. After you install a package, it stays on your iPad and works offline.
When a cell imports a package that isn’t installed, Lectra asks Install “package”? and offers to download it from PyPI. Tap Install.
You can install packages written only in Python. Packages that need compiled code, such as SciPy and scikit-learn, aren’t available on the iPad.

Work with files

  • In a notebook, use Data to bring in a CSV, TSV, or text file. To learn how, see Use Jupyter notebooks.
  • In a script, Python can read the text files in the folder you run it from, such as .py, .csv, .json, .txt, and .md files. It reads up to 400 files and 8 MB in total, and skips any file larger than 1 MB.
Files that Python creates, such as a CSV you write or a chart you save with savefig(), aren’t saved to your project or your library. In a notebook, charts appear below the cell instead. Copy any results you need before you close the notebook or terminal.

Stop or restart Python

  • In a notebook, tap More > Restart Kernel. This stops a running cell, or clears all your variables if nothing is running.
  • In the terminal, a running command finishes on its own. Pressing Control C doesn’t stop it.
If a single run takes longer than 3 minutes, Lectra stops waiting and shows “Python stopped responding”. If your iPad needs memory back, it can close Python and Lectra shows “The Python kernel was reclaimed by the system. Run it again to restart.”

Limits

Python runs inside Lectra on your iPad, so some things that work on a computer don’t work here:
  • Code that opens network connections, starts threads, or runs other programs doesn’t work.
  • The sqlite3, ssl, and lzma modules aren’t available.
  • In a notebook, input() doesn’t ask you for text. It returns an empty string. In the terminal, input() works.
  • Files that Python writes aren’t kept, as described in Work with files.
If you need a full Python setup, you can connect to another computer over SSH from the terminal. To learn how, see Use the terminal.

Troubleshooting

Python may still need its one-time download. Connect to the internet, and then run the cell again.
The package isn’t installed. Install it as described in Install more packages. If it needs compiled code, it isn’t available on the iPad.
The run took longer than 3 minutes, or Lectra was in the background for a while. Run it again. For long work, split it into smaller steps.
Files that Python writes aren’t kept. Print the results instead, or, in a notebook, show charts below the cell.

Use Jupyter notebooks

Create, open, and run .ipynb notebooks.

Use the terminal

Run scripts and use the built-in shell.