Getting a " NameError: name '_imp' is not defined " while try to plot plotly chart on streamlit window

I was trying to plot two variables dataframe in a chart using plotly graph objects. but when I ran it. it is giving _imp is not defined. I searched everywhere but I didn’t get my answer.

code:

        fig = go.Figure()

        fig.add_trace(go.Scatter(x=df['Cumulated_T']/3600,
                                y = df['Capacity'],
                                line = dict(color='purple',width=3))
                     )
        fig.update_layout(
                           title = 'Battery Discharge Capacity',
                           xaxis_title = 'Working time [hours]',
                           yaxis_title = 'Battery Capacity in Ahr')
        st.plotly_chart(fig)

Error:

   NameError: name '_imp' is not defined
    Traceback:
    File "d:\env\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 557, in _run_script
        exec(code, module.__dict__)
    File "battery_ui.py", line 53, in <module>
        fig = go.Figure()
    File "d:\env\lib\site-packages\plotly\graph_objs\_figure.py", line 594, in __init__
        super(Figure, self).__init__(data, layout, frames, skip_invalid, **kwargs)
    File "d:\env\lib\site-packages\plotly\basedatatypes.py", line 631, in __init__
        self._initialize_layout_template()
    File "d:\env\lib\site-packages\plotly\basedatatypes.py", line 2522, in _initialize_layout_template
        self._layout_obj.template = template_object
    File "d:\env\lib\site-packages\plotly\basedatatypes.py", line 5875, in __setattr__
        super(BaseLayoutHierarchyType, self).__setattr__(prop, value)
    File "d:\env\lib\site-packages\plotly\basedatatypes.py", line 4913, in __setattr__
        if prop.startswith("_") or hasattr(self, prop) or prop in self._valid_props:
    File "d:\env\lib\site-packages\plotly\graph_objs\_layout.py", line 3244, in template
        return self["template"]
    File "d:\env\lib\site-packages\plotly\basedatatypes.py", line 5832, in __getitem__
        return super(BaseLayoutHierarchyType, self).__getitem__(prop)
    File "d:\env\lib\site-packages\plotly\basedatatypes.py", line 4708, in __getitem__
        validator = self._get_validator(prop)
    File "d:\env\lib\site-packages\plotly\basedatatypes.py", line 4329, in _get_validator
        return ValidatorCache.get_validator(self._path_str, prop)
    File "d:\env\lib\site-packages\plotly\validator_cache.py", line 29, in get_validator
        importlib.import_module("plotly.validators." + parent_path),
    File "C:\Users\annamalai\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
    File "<frozen importlib._bootstrap>", line 988, in _find_and_load
    File "<frozen importlib._bootstrap>", line 148, in __enter__
    File "<frozen importlib._bootstrap>", line 163, in _get_module_lock

Hi @Annamalaisaravanan , thanks for submitting your issue! Looking at the error, it looks unrelated to streamlit. Have you tried running it in a separate python console and just trying that?
From my google search, I can’t seem to find anything substantial either :confused:

Hi @willhuang,
Thanks. I’ll try and let you know. is it because any incompatibility b/w stream lit and plotly version?

Hi @Annamalaisaravanan , I think we just upgraded our plotly version 14 days ago (Update plotly.js version (#5022) · streamlit/streamlit@bd406d0 · GitHub). This will come out in the official latest release which should be later this week on thursday.

If you want to test it out with the latest plotly upgrade, you can try it by installing the streamlit nightly (Pre-release features - Streamlit Docs)

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