MCoder
MCoder

Reputation: 73

No module named streamlit.__main__; ‘streamlit’ is a package and cannot be directly executed

When I try to deploy streamlit to heroku I get this below error. How can I fix it?

No module named streamlit.main; ‘streamlit’ is a package and cannot be directly executed

enter image description here

enter image description here

Upvotes: 4

Views: 4014

Answers (3)

Dali Tang
Dali Tang

Reputation: 31

I tried and this works for me:

python -m streamlit.cli run path/to/your/app.py

Upvotes: 3

Bandham Manikanta
Bandham Manikanta

Reputation: 2015

This will work for you too.. python -m streamlit.cli iris_eda_app.py

Upvotes: 1

Tim Conkling
Tim Conkling

Reputation: 121

The streamlit command lives in your virtualenv's bin/ folder. It looks like pipenv run isn't looking in that folder, and is instead finding the package called streamlit, and trying to execute that instead.

Without seeing any details of what your Heroku deployment looks like, it's hard to offer concrete advice to fix this issue. But from your screenshots, it looks like you're executing this command from within a pipenv shell. Since you're already in the shell, you don't need to use pipenv run streamlit run ... to run the streamlit command; having the shell activated means that the streamlit command will already be on your $PATH.

When you have the shell active, doing this should work instead:

streamlit run iris_eda_app.py

Alternately, you could forego pipenv and manage your virtualenv directly. I've put together a minimal working example of a Streamlit app that's deployable to Heroku. It uses a plain requirements.txt file instead of a Pipfile: https://github.com/tconkling/streamlit_heroku_example

Upvotes: 0

Related Questions