Getting "TypeError: a bytes-like object is required, not 'DeltaGenerator'" when using Pillow and Streamlit

Hello everyone. I’m using Pillow within streamlit in Python and I try to load an image with the following code

img_form = Image.open(dir_path + "/images/1.jpg")

And I get the following error

2022-06-30 19:47:28.483 Uncaught app exception
Traceback (most recent call last):
  File "/home/asdru/.cache/pypoetry/virtualenvs/streamlit-test-2drTybIu-py3.10/lib/python3.10/site-packages/streamlit/scriptrunner/script_runner.py", line 554, in _run_script
    exec(code, module.__dict__)
  File "/home/asdru/projects/streamlit-test/streamlit_test/app.py", line 65, in <module>
    st.image(image_column)
  File "/home/asdru/.cache/pypoetry/virtualenvs/streamlit-test-2drTybIu-py3.10/lib/python3.10/site-packages/streamlit/elements/image.py", line 138, in image
    marshall_images(
  File "/home/asdru/.cache/pypoetry/virtualenvs/streamlit-test-2drTybIu-py3.10/lib/python3.10/site-packages/streamlit/elements/image.py", line 423, in marshall_images
    proto_img.url = image_to_url(
  File "/home/asdru/.cache/pypoetry/virtualenvs/streamlit-test-2drTybIu-py3.10/lib/python3.10/site-packages/streamlit/elements/image.py", line 353, in image_to_url
    (data, mimetype) = _normalize_to_bytes(data, width, output_format)
  File "/home/asdru/.cache/pypoetry/virtualenvs/streamlit-test-2drTybIu-py3.10/lib/python3.10/site-packages/streamlit/elements/image.py", line 240, in _normalize_to_bytes
    image = Image.open(io.BytesIO(data))
TypeError: a bytes-like object is required, not 'DeltaGenerator'

I also tried opening the file using the following code and I get the same error.

img_form = Image.open(open(dir_path + "/images/1.jpg", "rb"))

Any help solving this is appreciated. For reference I’m using the following versions of these packages:

streamlit β†’ "1.10.0"
Pillow β†’ "9.1.1"

Also my Python version is 3.10.5. I’m using Manjaro Linux with kernel version5.18.6-1-MANJARO

Oh, I was using a different variable, that came from st.columns call, please ignore

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