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

Hello guys,

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

What versions of python are you running?

1 Like

Hey @M11, welcome to Streamlit!

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

1 Like

Hi,
Had the same problem. I donā€™t know if it is windows related but on my ubuntu everything was fine.

Anyway, what you can do is to change the cli.py filename to __main__.py.
This worked for me

Hi @Noam, welcome to the Streamlit community!

You shouldnā€™t need to rename anything, plenty of people are able to deploy on Heroku without needing to modify the source files.

Iā€™m having the same issue. Iā€™m running 3.9 within a conda environment.

Hi @madras,

Welcome to the streamlit forum :slight_smile:. Are you running streamlit 0.72.0?

Hi @SimonBiggs, Thank you for responding.

I was running 0.71.0 earlier. I removed the environment and re-created it by this command:

conda create -p .\StreamLitEnv python=3.8

Switched to the above environment and then re-installed with this command:
conda install -c conda-forge streamlit

It seemed to work at this point and it installed 0.72 version. I also had SSL_VERIFY set to false. Even though it is bad practice, thatā€™s the only way I could advance.

Out of curiosity, I tried this command:
pipenv install streamlit
This did not work. It failed with CERTIFICATE_VERIFY_FAILED errors.

My questions are:

  1. What is the command to update streamlit in future?
  2. How to get past the SSL errors? Iā€™ve imported all the certificates from pypi.org etc etc, into the local Certificate store, copied the 2 DLLs into the DLL folder etc.
  3. Is streamlit ready to be used with Python 3.9 ? If so, how to update the version in the environment?

(Iā€™m new to python, so I apologize for using incorrect terminology). Setting up the system to run streamlit took a lot of time and that is the most frustrating part. I enjoy coding with it.

Thank you for guidance.

Hi @Noam, can you share more information about your environment and how you installed it? Any of the below would be helpful.

  • Streamlit version: (get it with $ streamlit version)
  • Python version: (get it with $ python --version)
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version