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:- Downloading Python… with a percentage, the first time only.
- Starting Python…
- Python ready
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.- From a notebook cell
- From the Packages sheet
- From the terminal
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.mdfiles. It reads up to 400 files and 8 MB in total, and skips any file larger than 1 MB.
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.
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, andlzmamodules 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.
Troubleshooting
The notebook stays on Starting Python…
The notebook stays on Starting Python…
Python may still need its one-time download. Connect to the internet, and then run the cell again.
ModuleNotFoundError for a package
ModuleNotFoundError for a package
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.
“Python stopped responding”
“Python stopped responding”
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.
The file my script saved isn't there
The file my script saved isn't there
Files that Python writes aren’t kept. Print the results instead, or, in a notebook, show charts below the cell.
Related
Use Jupyter notebooks
Create, open, and run
.ipynb notebooks.Use the terminal
Run scripts and use the built-in shell.