Install Python Packages

Declare pinned app requirements or install a package from Python inside the Gradio Lite browser runtime.

The browser runtime includes Python, Gradio, and packages available through its Pyodide distribution. Declare an app requirement when your app needs another installable Python package.

A package is an installable distribution such as transformers-js-py. A module is the name used in Python import statements, such as transformers_js_py. Their names can differ.

Choose an installation path

Path Use it when Scope
gradio.requirements The document always needs the package Every embedded app in the document
micropip.install() The app decides what to install at runtime The worker that executes that source

Prefer document requirements for a predictable published app. Pin exact versions so a new package release cannot change app startup without a document change.

Declare document requirements

Add the requirement to the document’s YAML front matter:

gradio:
  requirements:
    - "plotly==5.24.1"

Then define the app:


::: {#5bedf546 .cell}
``` {.python .cell-code}
import gradio as gr
import plotly.express as px

datasets = {
    "iris": px.data.iris(),
    "gapminder": px.data.gapminder(),
    "tips": px.data.tips(),
}

def plot_figure(dataset):
    data = datasets[dataset]
    return px.scatter(
        data,
        x=data.columns[0],
        y=data.columns[1],
        color=data.columns[-1],
        title=f"{dataset.title()} dataset",
    )

gr.Interface(
    fn=plot_figure,
    inputs=gr.Dropdown(choices=list(datasets), value="iris"),
    outputs="plot",
    flagging_mode="never",
).launch()
```
:::

Choose a dataset and select Submit. The app returns a Plotly scatter plot.

Code
import gradio as gr
import plotly.express as px

datasets = {
    "iris": px.data.iris(),
    "gapminder": px.data.gapminder(),
    "tips": px.data.tips(),
}

def plot_figure(dataset):
    data = datasets[dataset]
    return px.scatter(
        data,
        x=data.columns[0],
        y=data.columns[1],
        color=data.columns[-1],
        title=f"{dataset.title()} dataset",
    )

gr.Interface(
    fn=plot_figure,
    inputs=gr.Dropdown(choices=list(datasets), value="iris"),
    outputs="plot",
    flagging_mode="never",
).launch()
plotly==5.24.1 import gradio as gr import plotly.express as px datasets = { "iris": px.data.iris(), "gapminder": px.data.gapminder(), "tips": px.data.tips(), } def plot_figure(dataset): data = datasets[dataset] return px.scatter( data, x=data.columns[0], y=data.columns[1], color=data.columns[-1], title=f"{dataset.title()} dataset", ) gr.Interface( fn=plot_figure, inputs=gr.Dropdown(choices=list(datasets), value="iris"), outputs="plot", flagging_mode="never", ).launch()

gradio.requirements is document-wide. In a document with several apps, the requirement list is included with every emitted app.

Install from Python

Micropip is Pyodide’s package installer. Use it when the app source needs to control installation directly:

Code
import micropip
await micropip.install("faker==37.8.0")

import gradio as gr
import pandas as pd
from faker import Faker

fake = Faker()
generators = {
    "Name": fake.name,
    "Address": fake.address,
    "Email": fake.email,
    "Phone": fake.phone_number,
    "Job": fake.job,
}

def generate_data(data_type, count):
    rows = [
        {"#": index + 1, "Data": generators[data_type]()}
        for index in range(count)
    ]
    return pd.DataFrame(rows)

demo = gr.Interface(
    fn=generate_data,
    inputs=[
        gr.Dropdown(list(generators), value="Name"),
        gr.Slider(1, 10, value=3, step=1),
    ],
    outputs=gr.Dataframe(wrap=True),
)
demo.launch()
plotly==5.24.1 import micropip await micropip.install("faker==37.8.0") import gradio as gr import pandas as pd from faker import Faker fake = Faker() generators = { "Name": fake.name, "Address": fake.address, "Email": fake.email, "Phone": fake.phone_number, "Job": fake.job, } def generate_data(data_type, count): rows = [ {"#": index + 1, "Data": generators[data_type]()} for index in range(count) ] return pd.DataFrame(rows) demo = gr.Interface( fn=generate_data, inputs=[ gr.Dropdown(list(generators), value="Name"), gr.Slider(1, 10, value=3, step=1), ], outputs=gr.Dataframe(wrap=True), ) demo.launch()

Choose a data type and count, then submit. The app installs Faker and returns generated rows.

Check compatibility

Pyodide can install pure Python wheels and packages built for its WebAssembly environment. A package that requires an unavailable native library will fail to install. Large packages and model downloads also increase first-start time.

When installation fails:

  1. Pin a version known to support Pyodide 0.27.3.
  2. Check the Pyodide package documentation.
  3. Inspect the visible Python error and browser console.
  4. Confirm that the package and wheel origins are reachable and allow cross-origin requests.

App requirements are separate from the extension’s runtime compatibility pins. The latter boot the frozen Gradio Lite environment and are not an author configuration surface.

See Runtime and Trust for the complete package and network boundary.