1

Trying to open a app using .bat file so that other users don't have to use a terminal to open the app. The bat file has the contents as below

  set root=C:\Users\***\Anaconda3
  call %root%\Scripts\activate.bat
  call conda activate dsatprediction
  call streamlit run "C:\Users\***\PycharmProjects\dsatpred\app.py"

When the file is run, it results in enter image description here

The same app runs using the command streamlit run app.py on terminal.

Any guidance is appreciated

Mr Rj
  • 41
  • 1
  • 10

3 Answers3

2

I managed to make mine work this way :

@ECHO OFF
set root=C:\Anaconda3
call %root%\Scripts\activate.bat
cd [PATH_TO_YOUR_STREAMLIT_APP_FOLDER]
pip install -r requirements.txt
call streamlit run app.py

Be sure to have Anaconda installed. Give that path to the root variable. Activate that conda environment. The path to your streamlit app is only to the folder, finished by a “” and does not include your .py script. This does not need to be between " " or between . Just copy-paste the path. I added the pip install -r requirements to force the update of the python libraries needed to run my app. This is not mandatory, but just makes your life easier. Finally, I simply call my app.

Your file can be located anywhere and the app runs fine.

0

I don't know what causes the error you see, but my batch file is done differently, maybe it can help you. I have gotten this code to run my files:

call C:\[anaconda_path_goes_here]\envs\[env_name_goes_here]\Scripts\activate.bat
C:\[anaconda_path_goes_here]\envs\[env_name_goes_here]\Scripts\streamlit.exe run [path_to_streamlit_file]\[name_of_streamlit_file].py

I install conda in my env and run the activate command directly in that env. Maybe it makes a difference. On the other hand, my streamlit apps don't open an files from the disk, so it may not solve your problem.

Nick W
  • 146
  • 9
-1
@ECHO OFF
call "C:\[full path the app folder]\venv\scripts\activate.bat"
cd C:\[full path to app folder]
streamlit run app.py
  • 1
    Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney May 08 '22 at 00:18