Executable from Pyinstaller works when launching in terminal, but not by double clicking

I have main.py:

import streamlit as st

st.text("This program is running")

And wrapper.py in the same dir:

import subprocess

subprocess.run(["streamlit", "run", "main.py"])

When I run the command pyinstaller --onefile --clean -w --add-data "main.py;." wrapper.py, an executable is created (without errors), and I can run this executable as .\dist\wrapper.exe, but when I double click it (in Windows), I get the following error:

Traceback (most recent call last):
  File "wrapper.py", line 9, in <module>
  File "subprocess.py", line 548, in run
  File "subprocess.py", line 1024, in __init__
  File "subprocess.py", line 1493, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

I have checked quite a few other posts in the forum about this topic, but couldn’t find a solution for my specific case. Does anyone have an idea?

I’m having this same issue

@danieljuschus also, I tried to create a .bat file to run the exe and still got the same error. Not sure what the issue is.

@danieljuschus I was able to get it working. Here’s a quick overview:

  • I used the wrapper code from here Streamlit application to EXE file | by Roberto Viegas Dutra | Medium
  • I also had to import streamlit.runtime.scriptrunner.magic_funcs in that same file
  • I kept getting package not found errors, so I had to copy paste the missing lib folders from my venv to the lib folder in the build folder
  • also note that doing this will have you start in dev mode. You can hide the deploy button using markdown.
`
![test|586x304](upload://noADDux6d8YdH1p1NkDQPktjKsK.png)
`

So you used cx_freeze instead of pyinstaller?

Did you want to post a screenshot?