does not plot altair chart from .py script


I have code in a .py script. Code for an altair chart. I want to plot it. I get an error instead

Steps to reproduce

Code snippet:

import pandas as pd
import numpy as np
import streamlit as st
import altair as alt

from datetime import time, datetime
from vega_datasets import data as vega_data

movies_df = pd.read_json(vega_data.movies.url)

def extract_year(value):
    return pd.to_datetime(value, format="%b %d %Y").year

movies_df['year'] = movies_df.Release_Date.apply(extract_year)

movies_2000 = movies_df.loc[movies_df.year == 2000]

chart = alt.Chart(movies_2000).mark_point().encode(
    tooltip=['Title', 'Production_Budget', 'Worldwide_Gross']

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Plotting the chart.

Actual behavior:
Traceback (most recent call last):
File β€œC:\Users\Hans\anaconda3\envs\streamlit-env\lib\site-packages\IPython\core\”, line 3508, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File β€œβ€, line 27, in
File β€œC:\Users\Hans\anaconda3\envs\streamlit-env\lib\site-packages\altair\vegalite\v5\”, line 2280, in show, embed_opt=embed_opt, open_browser=open_browser)
File β€œC:\Users\Hans\anaconda3\envs\streamlit-env\lib\site-packages\”, line 355, in show
msg = self.display(chart, embed_opt=embed_opt, open_browser=open_browser)
File β€œC:\Users\Hans\anaconda3\envs\streamlit-env\lib\site-packages\”, line 268, in display
raise RuntimeError(β€œInternal: _stream is not defined.”)
RuntimeError: Internal: _stream is not defined.

Debug info

  • Streamlit version:1.23.1
  • Python version: .10
  • Using Conda
  • OS version: WIndows
  • Browser version: Chrome

Requirements file


  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

Take a look at the Streamlit documentation on charts.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.