Problems with streamlit run after creating executable from pyinstaller

I am fairly new to streamlt functionality, and I have been following the using streamlit to create an executable and running it locally threads. Currently, my team and I are working on an application powered by a Large Language Model (LLM) using Streamlit. Our goal is to create an executable where the code is protected and unreadable to others. To achieve this, I’ve outlined a three-step process:

  1. Code Obfuscation: Utilizing PyArmor to obfuscate the code.
  2. Executable Creation: Using PyInstaller to turn the obfuscated code into an executable.
  3. Docker Image Creation: Packaging the entire executable within a Docker image.

I’ve successfully created the executable by modifying the .spec file, which resulted in a ‘streamlit_main’ executable file. However, I’ve encountered a significant challenge at this stage. When I attempt to run the executable using ./streamlit_main, I receive an error:
WARNING streamlit:
Warning: to view this Streamlit app on a browser, run it with the following
command:

streamlit run ./streamlit_main_query [ARGUMENTS]

2024-01-22 22:24:05.392 WARNING streamlit.runtime.state.session_state_proxy: Session state does not function when running a script without streamlit run.

Yet, executing this command leads to another error stating that streamlit run can only operate with Python files, the error I see is:
Error: Streamlit requires raw Python (.py) files, but the provided file has no extension.

I’m stuck because I can’t add any source code or Python files to this setup. Does anyone know a better way to do this? Any advice or tips would be really helpful.

I am facing exact same issue, has anyone figured out a solution to this issue?
System==macOS-14.0-23A344
Python==3.10.13
streamlit==1.30.0
pyinstaller==6.3.0

Hello @NitikGupta,

Since you cannot run the binary directly with streamlit run , maybe consider creating a Python bootstrap script that executes the binary.

  1. Create a Python Wrapper (wrapper.py)
import subprocess

subprocess.call(['./streamlit_main'])
  1. Use PyInstaller to compile wrapper.py into an executable
  2. Instead of running streamlit run ./streamlit_main , you’ll execute the wrapper script’s binary, which in turn launches your Streamlit app contained within the streamlit_main binary.

Hi @sahirmaharaj , I have created my main.exe file, and ran into a similar issue to OP. I tried your method to create a wrapper file with the following

import subprocess

subprocess.call(['dist\main.exe'])

I created a wrapper.exe using pyinstaller and upon clicking it, I get file error and it is unable to locate my file (I’m assuming main.exe).

When I do streamlit run wrapper.py, it opens my local host but get this error in my terminal and my app doesn’t show in the local host:

  Warning: to view this Streamlit app on a browser, run it with the following
  command:

    streamlit run dist\main.exe [ARGUMENTS]
WARNING streamlit.runtime.state.session_state_proxy: Session state does not function when running a script without `streamlit run`

Did I misunderstand your instructions, or perhaps I did something wrong? Thank you.