Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Streamlit 1.34] AttributeError: module 'streamlit.components' has no attribute 'v1' #8644

Open
4 tasks done
SiddhantSadangi opened this issue May 12, 2024 · 6 comments · May be fixed by #8666
Open
4 tasks done

[Streamlit 1.34] AttributeError: module 'streamlit.components' has no attribute 'v1' #8644

SiddhantSadangi opened this issue May 12, 2024 · 6 comments · May be fixed by #8666
Labels
feature:custom-components status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working type:docs Requests for changes to docs (will be rerouted to docs repo)

Comments

@SiddhantSadangi
Copy link

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

Streamlit v1.34 seems to have removed v1 from streamlit.components, leading to an AttributeError when trying to use streamlit.components.v1.html().

There is no mention of any such change in the changelog, and the documentation still includes v1.html() in v1.34.0: https://docs.streamlit.io/develop/api-reference/custom-components/st.components.v1.html

streamlit.html() does not support all features supported by components.v1.html(), like height, and is not a good enough substitute yet.

Reproducible Code Example

import streamlit as st
st.components.v1.html()

Steps To Reproduce

  1. Install Streamlit v1.34
pip install streamlit==1.34
  1. Run the below code
import streamlit as st
st.components.v1.html()

Expected Behavior

v1.html() should be an attribute of streamlit.components

Current Behavior

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'streamlit.components' has no attribute 'v1'

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.34.0
  • Python version: 3.8.15
  • Operating System: Windows 11
  • Browser: Edge

Additional Information

Using as streamlit._main._html() works.
Using as

from streamlit.components.v1 import html
html()

also works.

@SiddhantSadangi SiddhantSadangi added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels May 12, 2024
Copy link

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@raethlein
Copy link
Collaborator

Hey @SiddhantSadangi , the docs state to import and use it like this

import streamlit as st
import streamlit.components.v1 as components

components.html("example")

This works for me in version 1.34. Are you able to confirm that it works if you use the import as stated in the docs?

@SiddhantSadangi
Copy link
Author

Hey @raethlein
Thanks for the quick response!

Yes, it does work if imported as stated in the docs.

However, it'd be great if this change can be highlighted in the docs and the 1.34 changelog, as I have always been using it directly as streamlit.components.v1.html() with no issues until 1.34

@raethlein
Copy link
Collaborator

raethlein commented May 13, 2024

You are welcome 🙂

I have also investigated a little bit why this changed and it seems to be that this should never have been possible, and was made transiently available via this import: from streamlit.components.v1.components import ComponentRegistry. If you check out an older Streamlit-version and run it in a normal Python shell, the import like that was not possible, likely because server.py is not imported in that case 🫠

Screenshot 2024-05-13 at 10 49 38
Screenshot 2024-05-13 at 11 13 15

There seem to be some places where we indeed advocate it like this: st.components.v1.html() and even though it looks like this was only possible due to some weird aspects of the Python import system, I am sorry to hear that this caused troubles on your side! I will check-in with the docs team about this!

@SiddhantSadangi
Copy link
Author

That's weird 🫠

I get a different AttributeError on 1.34 (streamlit.components can be imported, but not components.v1)
image

And for some weird reason, it has stopped working for me with streamlit<1.34, with the same error as you see:
image

Anyway, I think you can close this issue and just vet any docs or marketing material referencing direct usage as streamlit.components.v1.html()

@raethlein raethlein added type:docs Requests for changes to docs (will be rerouted to docs repo) status:confirmed Bug has been confirmed by the Streamlit team and removed status:needs-triage Has not been triaged by the Streamlit team labels May 13, 2024
@raethlein raethlein linked a pull request May 15, 2024 that will close this issue
@euhake
Copy link

euhake commented May 24, 2024

run command

pip install streamlit==1.32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:custom-components status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working type:docs Requests for changes to docs (will be rerouted to docs repo)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants