> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Runner

> Run a Python script in your project and save what it writes, such as figures for your document.

Python scripts run in your browser, so the output appears right below the editor. Nothing needs to be set up.

**1. Create a script**

In the file tree, click the **New file** icon. Enter a name that ends in `.py` and click **Create**.

![The Add Files dialog with the name analysis.py](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-new-file.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=6be49974e488f7678604cc0644f43bdc)

A new Python file

The **Run** button and an output pane appear below the editor. The first time, the button stays disabled while Python loads.

**2. Run it**

Write your code and click **Run**. What the script prints appears in the output pane. You don't have to save first.

Files the script writes go into your project. A message tells you which, for example **results.txt saved to your project**, and the file appears in the file tree.

![A script in the editor, its printed output below, and the message results.txt saved to your project](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-output.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=28188ffe214aedd1203d2734891917f7)

The output and a saved file

**3. Stop a script**

While a script runs, **Run** becomes **Stop**. Click it to interrupt the script. The output pane ends with **Execution interrupted**.

![The Stop button and the output of a running script](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-stop.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=263af195efa53538f1e3b37b4fad6041)

A running script

## Use a figure in your document

Plots have no window to appear in, so save them to a file. For example:

```python theme={null}
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [1, 4, 9])
plt.savefig("figure.png")
```

`figure.png` appears in your project, ready for `\includegraphics{figure.png}`.

![figure.png open in the editor, with the message figure.png saved to your project](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-figure.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=8b0074f8d46a40a105a459a6c09caabf)

A saved plot

## Read your project's files

A script can open the files of your project by their path:

```python theme={null}
print(open("results.txt").read())
```

## If something goes wrong

**The script raises an error.** The error appears in red in the output pane, after anything the script printed before it.

![Printed text followed by a traceback in red](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-error.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=89ef60d790737fe01d6d69b1e0395e9e)

An error in a script

**`ModuleNotFoundError: No module named ...`.** Only the packages built into Pyodide are available, and packages installed with `pip` cannot be used. NumPy and Matplotlib are among those available, and the message links to the [full list](https://pyodide.org/en/stable/usage/packages-in-pyodide.html).

![A ModuleNotFoundError in the output pane](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-missing-package.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=5dbbfca95ee2b6984e2b3220e500231a)

A package that is not available


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.