Using PyInstaller (or similar) to create an executable

UPDATE Not yet solved, but almost, further help appreciated!!!

I created the following wrapper script to allow any script utilitzing streamlit to be run by calling
python streamlitWrapper.py.

import runpy
runpy.run_module('streamlit.cli')
import streamlit.cli
import click
click.pass_context
if __name__ == '__main__':
    streamlit.cli._main_run_clExplicit('pythonScript.py', 'streamlit run')

Save the 7 lines above into another script called streamlitWrapper.py (or any other name). You will also need to edit the file cli.py contained in the streamlit distribution to include the following def:

def _main_run_clExplicit(file, command_line, args=[]):
    streamlit._is_running_with_streamlit = True
    Credentials.get_current().check_activated(auto_resolve=True)
    if version.should_show_new_version_notice():
        click.echo(NEW_VERSION_TEXT)
        bootstrap.run(file, command_line, args)

After all that, you can run your script using the usual python call python streamlitWrapper.py.

The next step is to run:

pyinstaller streamlitWrapper.py

And with some massaging you should receive an executable.

The problem now is, the pyinstaller executable starts streamlit on port 3000 instead of port 8501 and my browser (for reasons I don’t understand) can’t run my script when using streamlitWrapper.exe (this is the default name of the executable pyinstaller will produce), running python streamlitWrapper.py works exactly the same as when calling streamlit run pythonScript.py, but for some reason the pyinstaller executable doesn’t exactly replicate the functionality you get when running python streamlitWrapper.py.

3 Likes