Jinja Error
This guide will walk you through resolving the Jinja2 version conflict and successfully running your Streamlit app in Deepnote.
Issue description
When running Streamlit commands, you might encounter the following error:
ImportError: Pandas requires version '3.0.0' or newer of 'jinja2' (version '2.11.3' currently installed).
Attempts to uninstall and reinstall Jinja2 may result in the following error:
Found existing installation: Jinja2 2.11.3
Not uninstalling jinja2 at /shared-libs/python3.10/py-core/lib/python3.10/site-packages, outside environment /root/venv
Can't uninstall 'Jinja2'. No files were found to uninstall.
Solution
Install the older version of streamlit for compatibility
import streamlit as st # !pip install streamlit==0.84.0
import openai
openai.api_key = st.secrets["openai_api_key"]
def generate_text(prompt):
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
max_tokens=50
)
return response.choices[0].text.strip()
st.title("LangChain and OpenAI Demo")
user_input = st.text_input("Enter a prompt:")
if user_input:
output = generate_text(user_input)
st.write(output)
In case you are still having struggles with jinja error verify you installation:
import streamlit as st
import jinja2
print("Streamlit version:", st.__version__)
print("Jinja2 version:", jinja2.__version__)
# Output: Streamlit version: 0.84.0
# Output: Jinja2 version: 2.11.3
Conclusion
By installing a compatible version of Streamlit, you can work around the Jinja2 version conflict and successfully run your Streamlit app with LangChain and OpenAI in Deepnote. This approach ensures that you can leverage Deepnote’s powerful features while maintaining compatibility with essential libraries.
If you encounter further issues, feel free to contact our support for assistance. Happy taking control over the world with AI in Deepnote!