Tried adding streamlit-extras to my environment.yml, but getting not found error when importing

I’ve added - streamlit-extras to my environment.yml and if I try to import anything in that package in my streamlit_app.pyfile like streamlit_app.py I get the following error message:

ModuleNotFoundError: No module named ‘streamlit_extras’

Traceback:

File "/tmp/appRoot/streamlit_app.py", line 4, in <module>
    from streamlit_extras import grid

I’ve also added the following code without the import to display all the installed packages and streamlit-extras is not displayed.

import pkg_resources
installed_packages = pkg_resources.working_set
for package in sorted(installed_packages, key=lambda x: x.key):
  st.write(f"{package.key}=={package.version}")

environment.yml

name: app_environment
channels:
  - snowflake
dependencies:
  - python=3.11.*
  - snowflake-snowpark-python=1.44.0
  - streamlit=1.52.2
  - streamlit-extras=0.6.0

streamlit_app.py

import streamlit as st
from streamlit_extras import grid
import pkg_resources

installed_packages = pkg_resources.working_set
for package in sorted(installed_packages, key=lambda x: x.key):
    st.write(f"{package.key}=={package.version}")

Hey there, thanks for sharing your question and the details! :balloon: The issue is that streamlit-extras is not available on Conda/Anaconda channels (like snowflake or conda-forge), so adding - streamlit-extras=0.6.0 to environment.yml will not install it. That’s why it’s missing from your installed packages and you get ModuleNotFoundError when importing it. You need to install streamlit-extras via pip, which is only possible by adding it under a pip: section in your environment.yml file, like this:

name: app_environment
channels:
  - snowflake
dependencies:
  - python=3.11.*
  - snowflake-snowpark-python=1.44.0
  - streamlit=1.52.2
  - pip
  - pip:
      - streamlit-extras==0.6.0

This tells Conda to use pip to install streamlit-extras after setting up the Conda environment. For more info, see the official Streamlit docs on installing non-Conda packages and ModuleNotFoundError troubleshooting.

Sources:

Streamlit-extras is in the anaconda snowflake channel that it uses: Snowflake Snowpark for Python

I did try adding what was suggested in into my streamlit in snowflake, but and got the following error (I don’t think you can use pip in Snowflake’s streamlit):

An error occurred while loading the app. Error: Unsupported Anaconda feature or malformed environment.yml file.

I then decided to try an older version streamlit-extras=0.4.0 and that worked. Seems like there is just something wrong with the 0.6.0 version in their channel. We’ve reached out to their support to let them know something is up in their environment / anaconda channel. I’ve tried using their channel locally, but haven’t been able to reproduce it yet. Guessing that when I try to create the environment it’s not completely locked down to that channel.

Appreciate the help, thank you.

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