Setting PYTHONPATH on Streamlit Cloud

Hello :wave:!

I have a streamlit app that lives as a module in a github repo. For example

|-- my-repo
    |-- mypackage/ # some custom python package
    |-- streamlit/ # streamlit stuff
        |-- pages/
        |-- pyproject.toml

I want to import mypackage in my streamlit app, which I can easily do locally by adding it to the PYTHONPATH prior to running streamlit.

cd my-repo
PYTHONPATH=$(PYTHONPATH):`pwd`/. streamlit run streamlit/

In Streamlit Cloud you can influence the app environment variables is via app settings, which I tried by setting the PYTHONPATH accordingly

PYTHONPATH = "/app/<my-repo>"

However this does not seem to work, and the import of mypackage fails in the cloud deployment.

Am I right in assuming that this should work? Is there a fix or workaround that I can try instead?

1 Like