Error does not seem to be in my code

Hello, my deployment on streamlit is getting this error:

Exception in thread ScriptRunner.scriptThread:

Traceback (most recent call last):

  File "/usr/local/lib/python3.7/threading.py", line 926, in _bootstrap_inner

    self.run()

  File "/usr/local/lib/python3.7/threading.py", line 870, in run

    self._target(*self._args, **self._kwargs)

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 182, in _process_request_queue

    widget_states = self._session_state.as_widget_states()

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/state/session_state.py", line 435, in as_widget_states

    return self._new_widget_state.as_widget_states()

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/state/session_state.py", line 188, in as_widget_states

    for widget_id in self.states.keys()

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/state/session_state.py", line 189, in <listcomp>

    if self.get_serialized(widget_id)

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/state/session_state.py", line 169, in get_serialized

    serialized = metadata.serializer(item.value)

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/elements/multiselect.py", line 138, in serialize_multiselect

    return _check_and_convert_to_indices(options, value)

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/elements/multiselect.py", line 121, in _check_and_convert_to_indices

    return [options.index(value) for value in default_values]

  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/elements/multiselect.py", line 121, in <listcomp>

    return [options.index(value) for value in default_values]

AttributeError: 'numpy.ndarray' object has no attribute 'index'

main

Any idea how to sort this?

Did this used to work?

You may need to share your app code.

As a wild guess, if you are using a multiselect widget, and using a data frame or a numpy array as a list of options to the widget, try wrapping it in a list() call first.

2 Likes

Thanks, I tried this but to no avail. Might need to use an alternative deployment provider.

After some tinkering, this now works. Thanks for your help

Brilliant, good to hear!

Hello I’m seeing this problem too. What do you mean by wrapping it in a list() call?

It will very much depend on exactly what you are trying to do - this post was from a year ago, since which streamlit has changed enormously, and the original problem never actually included any example code or a follow-up to diagnose the actual problem.

And my suggestion was a wild guess based on the non specific error message shown.

However, if you’d still like to try, it was based on this assumption:

You are using some sort of multiselect steamlit widget.

You are providing the options as an object like a numpy array or a pandas series or dataframe.

If so, try wrapping this object in a list() call - what this does is generate a python list from your object containing the options that you want to use in the widget.

For example, if your options were in the dataframe options_df then instead of using this as an argument to the streamlit widget, use list(options_df)

If this still doesn’t make sense, or doesn’t solve your problem, I think you would be best advised to start a new thread.

Best of luck :+1: