You’re encountering the error because the library you’re importing (sketch) imports another library (lambdaprompt) that uses async functions. But Streamlit runs in a separate thread that doesn’t have an event loop by default. To make it work, you’ll need to create an event loop and run the async functions inside it.
The lambdaprompt library runs some async code during the import process itself. So you can try creating an event loop before importing the library. Here’s an example:
import asyncio
from contextlib import contextmanager
import streamlit as st
# Create a context manager to run an event loop
@contextmanager
def setup_event_loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
yield loop
finally:
loop.close()
asyncio.set_event_loop(None)
# Use the context manager to create an event loop
with setup_event_loop() as loop:
import sketch
# Now you can use the 'sketch' library in your Streamlit app
st.write("The 'sketch' library has been successfully imported.")
I’m not 100% sure this is the right approach as I don’t have prior experience running async code in Streamlit. I’ll defer to the community to correct me.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.