Error import streamlit

error:
TypeError: init() got an unexpected keyword argument ‘serialized_options’
when import streamlit in python3 , w10, anaconda jupyter or cmd console to run py program?
What is solution (step ba step, mybe versions)?
Thanks in advance ,
Isaco

Hi @isaco

A few questions:

  1. What script are you trying to run when you see that error? Is it streamlit hello? Or is it a script you wrote?
  2. If a script you wrote, can you paste it here?
  3. Can you share the full error? There are usually some lines above the one you sent, which are important to help debug it.

Thanks!

Hi Thiago,

  1. both not working: streamlit hello.py, and example slider.py:

  2. slider.py:

import streamlit as st

x = st.slider(‘x’)
st.write(x, ‘squared is’, x * x)

V V ned., 20. okt. 2019 ob 23:45 je oseba Thiago Teixeira via Streamlit streamlit@discoursemail.com napisala:

Hi Thiago,

  1. both not working: streamlit hello.py, and example slider.py ?

  2. slider.py:

import streamlit as st

x = st.slider(‘x’)
st.write(x, ‘squared is’, x * x)

  1. error in jupyter (anaconda, w10, python 3.6.5):

TypeError Traceback (most recent call last)

<ipython-input-1-1aa3dc4fa683> in <module>
----> 1 import streamlit as st
~\Anc3\lib\site-packages\streamlit\__init__.py in <module>
     94 from streamlit import util as _util
     95 from streamlit.ReportThread import get_report_ctx, add_report_ctx
---> 96 from streamlit.DeltaGenerator import DeltaGenerator as _DeltaGenerator
     97
     98 # Modules that the user should have access to.

~\Anc3\lib\site-packages\streamlit\DeltaGenerator.py in <module>
     33 from streamlit import caching
     34 from streamlit import metrics
---> 35 from streamlit.proto import Balloons_pb2
     36 from streamlit.proto import BlockPath_pb2
     37 from streamlit.proto import ForwardMsg_pb2
~\Anc3\lib\site-packages\streamlit\proto\Balloons_pb2.py in <module>
     20   syntax='proto3',
     21   serialized_options=None,
---> 22   serialized_pb=_b('\n\x1estreamlit/proto/Balloons.proto\"\x8e\x01\n\x08\x42\x61lloons\x12\x1c\n\x04type\x18\x01 \x01(\x0e\x32\x0e.Balloons.Type\x12\x14\n\x0c\x65xecution_id\x18\x02 \x01(\r\"N\n\x04Type\x12\x0b\n\x07\x44\x45\x46\x41ULT\x10\x00\x12\x0b\n\x07\x42\x41LLOON\x10\x01\x12\x0e\n\nHAPPY_FACE\x10\x02\x12\r\n\tSTAR_FACE\x10\x03\x12\r\n\tCOOL_FACE\x10\x04\x62\x06proto3')
     23 )
     24

TypeError: __init__() got an unexpected keyword argument 'serialized_options'

3. attached error in CMD (the same)

Maybe versions, I done a lot of pip instalation of other packages (tensorflow (2.0), keras...).
Please advice me to solve the error! Thank you in advance, Isaco

V V pon., 21. okt. 2019 ob 09:22 je oseba Isaco Val myisaco@gmail.com napisala:

Hi @isaco - it sounds to me like your Python environment might have conflicting packages in it.

Could you try running streamlit from within a clean virtualenv? Here’s how you can set that up, assuming you’re using python3 on Windows:

  1. Create a new virtual environment called ‘venv’: python3 -m venv venv
  2. Activate your venv: venv\Scripts\activate.bat
  3. Install streamlit into your virtualenv: pip install streamlit (note that, since you activated your virtualenv in step 2, pip install will put streamlit and its dependencies into your venv, rather than in the global python packages directory).
  4. Run streamlit: streamlit hello

If you prefer Anaconda, or are already using it, this page is useful for getting up to speed on creating a new Anaconda environment: https://docs.anaconda.com/anaconda/navigator/tutorials/manage-environments/

(And you can read more about venv creation in the Python docs, here: https://docs.python.org/3/library/venv.html)

In general, installing everything into your global Python packages is bad practice, because it can result in all sorts of conflicts. In the case of your error, it looks like there may be a conflict in protobuf, a common library that Streamlit uses for data serialization. I wonder if you’d previously installed another package that uses a different version of protobuf?

After trying the above steps, if you’re still having issues, please feel free to post back here with your results!

2 Likes

@isaco - as a potential, quicker workaround: you could also try pip install --upgrade protobuf to get the latest protobuf dependency, without setting up a clean virtual environment.

If this doesn’t solve your problem, then I’d suggest going through the virtualenv steps above!

1 Like