> ## 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

> 프로젝트에서 Python 스크립트를 실행하고, 문서에 쓸 그림 등 스크립트가 쓴 결과를 저장합니다.

Python 스크립트는 브라우저에서 실행되므로 출력이 편집기 바로 아래에 표시됩니다. 별도로 설정할 것은 없습니다.

**1. 스크립트 만들기**

파일 트리에서 **New file** 아이콘을 클릭합니다. `.py`로 끝나는 이름을 입력하고 **Create**를 클릭합니다.

![이름이 analysis.py인 Add Files 대화 상자](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-new-file.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=6be49974e488f7678604cc0644f43bdc)

새 Python 파일

편집기 아래에 **Run** 버튼과 출력 창이 나타납니다. 처음에는 Python이 로드되는 동안 버튼이 비활성화되어 있습니다.

**2. 실행하기**

코드를 작성하고 **Run**을 클릭합니다. 스크립트가 출력한 내용이 출력 창에 표시됩니다. 먼저 저장할 필요는 없습니다.

스크립트가 쓴 파일은 프로젝트에 저장됩니다. 어떤 파일인지 메시지로 알려 주며(예: **results.txt saved to your project**), 파일이 파일 트리에도 나타납니다.

![편집기의 스크립트, 그 아래의 출력, 그리고 메시지 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)

출력과 저장된 파일

**3. 스크립트 중지하기**

스크립트가 실행되는 동안 **Run**은 **Stop**으로 바뀝니다. 클릭하면 스크립트가 중단됩니다. 출력 창은 **Execution interrupted**로 끝납니다.

![Stop 버튼과 실행 중인 스크립트의 출력](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-stop.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=263af195efa53538f1e3b37b4fad6041)

실행 중인 스크립트

## 문서에서 그림 사용하기

플롯을 표시할 창이 없으므로 파일로 저장합니다. 예:

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

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

`figure.png`가 프로젝트에 나타나며 바로 `\includegraphics{figure.png}`에 사용할 수 있습니다.

![편집기에서 열린 figure.png와 메시지 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)

저장된 플롯

## 프로젝트 파일 읽기

스크립트는 경로로 프로젝트의 파일을 열 수 있습니다:

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

## 문제가 생겼을 때

**스크립트에서 오류가 발생합니다.** 오류는 출력 창에 빨간색으로, 스크립트가 그 전에 출력한 내용 뒤에 표시됩니다.

![출력된 텍스트 뒤에 빨간색 트레이스백](https://mintcdn.com/ayakaleaf-pro/PeD9iteXIf8j4GXw/images/on-premises/python-runner-error.png?fit=max\&auto=format\&n=PeD9iteXIf8j4GXw\&q=85\&s=89ef60d790737fe01d6d69b1e0395e9e)

스크립트의 오류

**`ModuleNotFoundError: No module named ...`.** Pyodide에 내장된 패키지만 사용할 수 있으며 `pip`로 설치한 패키지는 사용할 수 없습니다. NumPy와 Matplotlib은 사용할 수 있으며, 메시지에 [전체 목록](https://pyodide.org/en/stable/usage/packages-in-pyodide.html) 링크가 있습니다.

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

사용할 수 없는 패키지


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